MCPcopy Index your code
hub / github.com/gpujs/gpu.js / scan

Method scan

src/backend/function-tracer.js:123–306  ·  view source on GitHub ↗

* Recursively scans AST for declarations and functions, and add them to their respective context * @param ast

(ast)

Source from the content-addressed store, hash-verified

121 * @param ast
122 */
123 scan(ast) {
124 if (!ast) return;
125 if (Array.isArray(ast)) {
126 for (let i = 0; i < ast.length; i++) {
127 this.scan(ast[i]);
128 }
129 return;
130 }
131 switch (ast.type) {
132 case 'Program':
133 this.useFunctionContext(() => {
134 this.scan(ast.body);
135 });
136 break;
137 case 'BlockStatement':
138 this.newContext(() => {
139 this.scan(ast.body);
140 });
141 break;
142 case 'AssignmentExpression':
143 case 'LogicalExpression':
144 this.scan(ast.left);
145 this.scan(ast.right);
146 break;
147 case 'BinaryExpression':
148 this.scan(ast.left);
149 this.scan(ast.right);
150 break;
151 case 'UpdateExpression':
152 if (ast.operator === '++') {
153 const declaration = this.getDeclaration(ast.argument.name);
154 if (declaration) {
155 declaration.suggestedType = 'Integer';
156 }
157 }
158 this.scan(ast.argument);
159 break;
160 case 'UnaryExpression':
161 this.scan(ast.argument);
162 break;
163 case 'VariableDeclaration':
164 if (ast.kind === 'var') {
165 this.useFunctionContext(() => {
166 ast.declarations = utils.normalizeDeclarations(ast);
167 this.scan(ast.declarations);
168 });
169 } else {
170 ast.declarations = utils.normalizeDeclarations(ast);
171 this.scan(ast.declarations);
172 }
173 break;
174 case 'VariableDeclarator': {
175 const { currentContext } = this;
176 const inForLoopInit = this.hasState(states.inForLoopInit);
177 const declaration = {
178 ast: ast,
179 context: currentContext,
180 name: ast.id.name,

Callers 1

constructorMethod · 0.95

Calls 8

useFunctionContextMethod · 0.95
newContextMethod · 0.95
getDeclarationMethod · 0.95
hasStateMethod · 0.95
pushStateMethod · 0.95
popStateMethod · 0.95
getIdentifiersMethod · 0.95
isStateMethod · 0.95

Tested by

no test coverage detected