Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
81 lines (63 loc) · 2.19 KB

File metadata and controls

81 lines (63 loc) · 2.19 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// This example will be made more sophisticated later, for now it just
// modifies the indentation of nested code blocks (from 2 spaces/block
// to 5 spaces/block).
#include "rose.h"
#include "unparseFormatHelp.h"
class CustomCodeFormat : public UnparseFormatHelp
{
public:
CustomCodeFormat();
~CustomCodeFormat();
virtual int getLine( SgLocatedNode*, SgUnparse_Info& info, FormatOpt opt);
virtual int getCol ( SgLocatedNode*, SgUnparse_Info& info, FormatOpt opt);
// return the value for indentation of code (part of control over style)
virtual int tabIndent ();
// return the value for where line wrapping starts (part of control over style)
virtual int maxLineLength ();
private:
int defaultLineLength;
int defaultIndentation;
};
CustomCodeFormat::CustomCodeFormat()
{
// default values here!
defaultLineLength = 20;
defaultIndentation = 5;
}
CustomCodeFormat::~CustomCodeFormat()
{}
// return: > 0: start new lines; == 0: use same line; < 0:default
int
CustomCodeFormat::getLine( SgLocatedNode*, SgUnparse_Info& info, FormatOpt opt)
{
// Use default mechanism to select the line where to output generated code
return -1;
}
// return starting column. if < 0, use default
int
CustomCodeFormat::getCol( SgLocatedNode*, SgUnparse_Info& info, FormatOpt opt)
{
// Use default mechanism to select the column where to output generated code
return -1;
}
int
CustomCodeFormat::tabIndent()
{
// Modify the indentation of the generated code (trival example of tailoring code generation)
return defaultIndentation;
}
int
CustomCodeFormat::maxLineLength()
{
return defaultLineLength;
}
int main (int argc, char* argv[])
{
// Initialize and check compatibility. See Rose::initialize
ROSE_INITIALIZE;
// Build the project object (AST) which we will fill up with multiple files and use as a
// handle for all processing of the AST(s) associated with one or more source files.
SgProject* project = new SgProject(argc,argv);
CustomCodeFormat* formatControl = new CustomCodeFormat();
return backend(project,formatControl);
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.