Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8626ae7459d4f5586cfc23f6721d3c16e169525e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <link rel="STYLESHEET" href="../../book.css" charset="ISO-8859-1"
 type="text/css">
  <title>CDT Programmer's Guide</title>
</head>
<body>
<p><span style="font-style: italic;">Note: This is a work in progress
for CDT 3.0. Changes should be expected until further notified.</span><br>
</p>
<h1>CDT DOM</h1>
<p>What is a DOM? Well, let me tell you. The DOM, or Document Object
Model, is a programmatic way to see the underlying source code in both
a syntactic and semantic view using an Abstract Syntax Tree (AST) and
to allow changes in the AST to be reflected back out to the source
code.<br>
</p>
<h2>Syntactic View</h2>
<p>The syntactic view (which we sometimes call the physical view)
represents the syntactic structure of the program. This is driven
mainly by the grammar that the parser follows, mapping from terminals
up to the entry rule in the grammer. This view fulfills the role of a
traditional Abstract Syntax Tree, and you'll see that the classes that
make up this view have AST in their name.<br>
</p>
<p>The top node of the Syntactic View is <a
 href="../../reference/api/org/eclipse/cdt/core/dom/ast/IASTTranslationUnit.html">IASTTranslationUnit</a>.
The translation unit object can be accessed from the C Model's <a
 href="../../reference/api/org/eclipse/cdt/core/model/ITranslationUnit.html">ITranslationUnit</a>
object.<br>
</p>
<h2>Semantic View</h2>
<p>The semantic view (which we sometimes call the logical view)
represent semantic elements in the program. These elements are
generally types, variables, and functions. The JDT calls these things
bindings, so we do to. However, the more general rule is that anything
that links sub-branches of the AST is a binding.<br>
</p>
<p>The most common way to get from the Syntactic View is to navigate
from an <a
 href="../../reference/api/org/eclipse/cdt/core/dom/ast/IASTName.html">IASTName</a>
view to the <a
 href="../../reference/api/org/eclipse/cdt/core/dom/ast/IBinding.html">IBinding</a>
that represents the Semantic object for that
given name.<br>
</p>
<h2>Workspace-Wide View</h2>
<p>Once you have a binding, it is possible to find all translation
units that declare or refer to that binding. From there you can
navigate from the IASTTranslationUnit to the IASTNames that declare or
refer to that binding.<br>
</p>
<h2>Rewriting</h2>
<p>From the Syntactic view, you can ask the AST Rewriter to calculate
the TextEdits required to accomplish changes to the AST.<br>
</p>
</body>
</html>

Back to the top