Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
SkShaderUtils::GLSLPrettyPrint Class Reference

Public Member Functions

 GLSLPrettyPrint ()
 
std::string prettify (const std::string &string)
 

Detailed Description

Definition at line 22 of file SkShaderUtils.cpp.

Constructor & Destructor Documentation

◆ GLSLPrettyPrint()

SkShaderUtils::GLSLPrettyPrint::GLSLPrettyPrint ( )
inline

Definition at line 24 of file SkShaderUtils.cpp.

24{}

Member Function Documentation

◆ prettify()

std::string SkShaderUtils::GLSLPrettyPrint::prettify ( const std::string &  string)
inline

Definition at line 26 of file SkShaderUtils.cpp.

26 {
27 fTabs = 0;
28 fFreshline = true;
29
30 // If a string breaks while in the middle 'parse until' we need to continue parsing on the
31 // next string
32 fInParseUntilNewline = false;
33 fInParseUntil = false;
34
35 int parensDepth = 0;
36
37 // setup pretty state
38 fIndex = 0;
39 fLength = string.length();
40 fInput = string.c_str();
41
42 while (fLength > fIndex) {
43 /* The heart and soul of our prettification algorithm. The rules should hopefully
44 * be self explanatory. For '#' and '//' tokens, we parse until we reach a newline.
45 *
46 * For long style comments like this one, we search for the ending token. We also
47 * preserve whitespace in these comments WITH THE CAVEAT that we do the newlines
48 * ourselves. This allows us to remain in control of line numbers, and matching
49 * tabs. Existing tabs in the input string are copied over too, but this will look
50 * funny.
51 *
52 * '{' and '}' are handled in basically the same way. We add a newline if we aren't
53 * on a fresh line, dirty the line, then add a second newline, i.e. braces are always
54 * on their own lines indented properly.
55 *
56 * '(' and ')' are basically ignored, except as a sign that we need to ignore ';', since
57 * we want to keep for loops on a single line.
58 *
59 * ';' means add a new line. If the previous character was a '}', we make sure that the
60 * semicolon comes directly after the brace, not on a newline.
61 *
62 * ',' doesn't add a new line, but does have special handling to ensure it is on the
63 * same line as a '}', much like the semicolon.
64 *
65 * '\t' and '\n' are ignored in general parsing for backwards compatibility with
66 * existing shader code. We also have a special case for handling whitespace at the
67 * beginning of fresh lines.
68 *
69 * Otherwise, just add the new character to the pretty string, indenting if
70 * necessary.
71 */
72 if (fInParseUntilNewline) {
73 this->parseUntilNewline();
74 continue;
75 }
76 if (fInParseUntil) {
77 this->parseUntil(fInParseUntilToken);
78 continue;
79 }
80 if (this->hasToken("#") || this->hasToken("//")) {
81 this->parseUntilNewline();
82 continue;
83 }
84 if (this->hasToken("/*")) {
85 this->parseUntil("*/");
86 continue;
87 }
88 if (fInput[fIndex] == '{') {
89 this->newline();
90 this->appendChar('{');
91 fTabs++;
92 this->newline();
93 continue;
94 }
95 if (fInput[fIndex] == '}') {
96 fTabs--;
97 this->newline();
98 this->appendChar('}');
99 this->newline();
100 continue;
101 }
102 if (fFreshline && fInput[fIndex] == ';') {
103 this->undoNewlineAfter('}');
104 this->appendChar(fInput[fIndex]);
105 this->newline();
106 continue;
107 }
108 if (fFreshline && fInput[fIndex] == ',') {
109 this->undoNewlineAfter('}');
110 this->appendChar(fInput[fIndex]);
111 continue;
112 }
113 if (this->hasToken(")")) {
114 parensDepth--;
115 continue;
116 }
117 if (this->hasToken("(")) {
118 parensDepth++;
119 continue;
120 }
121 if (this->hasToken(")")) {
122 parensDepth--;
123 continue;
124 }
125 if (!parensDepth && this->hasToken(";")) {
126 this->newline();
127 continue;
128 }
129 if (fInput[fIndex] == '\t' || fInput[fIndex] == '\n' ||
130 (fFreshline && fInput[fIndex] == ' ')) {
131 fIndex++;
132 continue;
133 }
134
135 this->appendChar(fInput[fIndex]);
136 }
137
138 return fPretty;
139 }

The documentation for this class was generated from the following file: