11package ko .carbonel .compiler .intermediate .tinyRust ;
22
3- import ko .carbonel .Logger ;
43import ko .carbonel .compiler .exception .semantic .MethodRedeclaredError ;
54import ko .carbonel .compiler .intermediate .SymbolTable ;
65import ko .carbonel .compiler .intermediate .tinyRust .ast .expression .*;
@@ -76,7 +75,6 @@ public void addMethod() {
7675 activeMethod .setParentScope (activeClass );
7776 activeMethod .block = (BlockStatementEntry ) statementStack .pop ();
7877 activeClass .addMethod (activeMethod );
79- Logger .output ("Adding method " + activeMethod .name .lexeme () + " to class " + activeClass .name .lexeme () + " with " + activeMethod .parameters .size () + " parameters and " + activeMethod .variables .size () + " variables returning " + activeMethod .returnType + " it has " + activeMethod .block .statements .size () + " statements" );
8078 activeMethod = new MethodEntry (this , null );
8179 }
8280
@@ -128,23 +126,20 @@ public void checkExpressions() {
128126 public void newIf () {
129127 IfStatementEntry newIf = new IfStatementEntry ();
130128 statementStack .push (newIf );
131- Logger .output ("New if" );
132129 }
133130
134131 @ CalledByParser
135132 public void ifBlock () {
136133 IfStatementEntry active = (IfStatementEntry ) statementStack .peek ();
137134 ExpressionEntry condition = expressionStack .pop ();
138135 active .setIfCondition (condition );
139- Logger .output ("If condition set" );
140136 }
141137
142138 @ CalledByParser
143139 public void ifElse () {
144140 StatementEntry body = statementStack .pop ();
145141 IfStatementEntry iF = (IfStatementEntry ) statementStack .peek ();
146142 iF .setIfBody (body );
147- Logger .output ("If body set" );
148143 }
149144
150145 @ CalledByParser
@@ -153,7 +148,6 @@ public void ifEnd() {
153148 IfStatementEntry iF = (IfStatementEntry ) statementStack .peek ();
154149 if (iF .body () == null ) iF .setIfBody (someBody ); // If there is no body yet, that means there is no else
155150 else iF .setElseBody (someBody );
156- Logger .output ("If close" );
157151 }
158152
159153 @ CalledByParser
@@ -207,7 +201,6 @@ public void whileBody() {
207201 @ CalledByParser
208202 public void expWrapBin (List <TinyRustLexerToken > op ) {
209203 if (op .size () != 1 ) throw new RuntimeException ("Operator size is not 1" );
210- Logger .output ("Operator: " + op .get (0 ).lexeme ());
211204 BinaryExpressionEntry nw = new BinaryExpressionEntry ();
212205 nw .setLeft (expressionStack .pop ());
213206 nw .setOperator (op .get (0 ));
@@ -219,21 +212,18 @@ public void expBinComplete() {
219212 ExpressionEntry rhs = expressionStack .pop ();
220213 BinaryExpressionEntry nw = (BinaryExpressionEntry ) expressionStack .peek ();
221214 nw .setRight (rhs );
222- Logger .output ("Binary expression: " + nw );
223215 }
224216
225217 @ CalledByParser
226218 public void expLit (List <TinyRustLexerToken > lit ) {
227219 if (lit .size () != 1 ) throw new RuntimeException ("Literal size is not 1" );
228- Logger .output ("Literal: " + lit .get (0 ).lexeme ());
229220 LiteralExpressionEntry exp = new LiteralExpressionEntry ();
230221 exp .setLiteral (lit .get (0 ));
231222 expressionStack .push (exp );
232223 }
233224
234225 @ CalledByParser
235226 public void expClassRef (TinyRustLexerToken lit ) {
236- Logger .output ("Class Ref: " + lit .lexeme ());
237227 ClassRefEntry exp = new ClassRefEntry ();
238228 exp .setName (lit );
239229 expressionStack .push (exp );
@@ -247,15 +237,13 @@ public void expField(TinyRustLexerToken lit) {
247237 @ CalledByParser
248238 public void expField (List <TinyRustLexerToken > lit ) {
249239 if (lit .size () != 1 ) throw new RuntimeException ("Literal size is not 1" );
250- Logger .output ("Field: " + lit .get (0 ).lexeme ());
251240 FieldAccessEntry exp = new FieldAccessEntry ();
252241 exp .setFieldName (lit .get (0 ));
253242 expressionStack .push (exp );
254243 }
255244
256245 @ CalledByParser
257246 public void expChainWith (TinyRustLexerToken id ) {
258- Logger .output ("Chain with: " + id .lexeme ());
259247 ChainedExpressionEntry chain = new ChainedExpressionEntry ();
260248 FieldAccessEntry lit = new FieldAccessEntry ();
261249 lit .setFieldName (id );
@@ -266,7 +254,6 @@ public void expChainWith(TinyRustLexerToken id) {
266254
267255 @ CalledByParser
268256 public void expReverseChain (TinyRustLexerToken id ) {
269- Logger .output ("Chain with: " + id .lexeme ());
270257 ChainedExpressionEntry chain = new ChainedExpressionEntry ();
271258 ClassRefEntry lit = new ClassRefEntry ();
272259 lit .setName (id );
@@ -277,10 +264,9 @@ public void expReverseChain(TinyRustLexerToken id) {
277264
278265 @ CalledByParser
279266 public void endChainMethod () {
280- MethodCallExpressionEntry method = (MethodCallExpressionEntry ) expressionStack .pop ();
267+ AttributeAccessEntry method = (MethodCallExpressionEntry ) expressionStack .pop ();
281268 if (expressionStack .isEmpty ()) {
282269 expressionStack .push (method );
283- Logger .output ("Method call UNCHAINED: " + method );
284270 return ; // was not chained
285271 }
286272 ExpressionEntry expr = expressionStack .pop ();
@@ -302,22 +288,19 @@ public void expArrayAccess() {
302288 public void newBlock () {
303289 BlockStatementEntry block = new BlockStatementEntry ();
304290 statementStack .push (block );
305- Logger .output ("New Block" );
306291 }
307292
308293 @ CalledByParser
309294 public void endBlock () {
310295 popStatementUntil (BlockStatementEntry .class , (block , statements ) -> {
311296 block .setStatements (statements );
312- Logger .output ("Block: " + block );
313297 });
314298 }
315299
316300 @ CalledByParser
317301 public void endExpr () {
318302 ExpressionStatementEntry exp = (ExpressionStatementEntry ) statementStack .peek ();
319303 exp .setExpression (expressionStack .pop ());
320- Logger .output ("Expression: " + exp );
321304 }
322305
323306 @ CalledByParser
@@ -327,18 +310,15 @@ public void expWrapUn(List<TinyRustLexerToken> op) {
327310 nw .setOperator (op .get (0 ));
328311 nw .setExpression (expressionStack .pop ());
329312 expressionStack .push (nw );
330- Logger .output ("Unary expression: " + nw );
331313 }
332314
333315 @ CalledByParser
334316 public void endMain () {
335- Logger .output ("Main end " + activeMethod .name );
336317 activeMethod .block = (BlockStatementEntry ) statementStack .pop ();
337318 }
338319
339320 @ CalledByParser
340321 public void endWhile () {
341- Logger .output ("While end" );
342322 StatementEntry pop = statementStack .pop ();
343323 WhileStatementEntry whileStatement = (WhileStatementEntry ) statementStack .peek ();
344324 whileStatement .setWhileBody (pop );
@@ -348,23 +328,20 @@ public void endWhile() {
348328 public void endReturn () {
349329 ReturnStatementEntry ret = (ReturnStatementEntry ) statementStack .peek ();
350330 ret .setReturnExpression (expressionStack .pop ());
351- Logger .output ("Return: " + ret );
352331 }
353332
354333 @ CalledByParser
355334 public void expMethodCall () {
356- ExpressionEntry pop = expressionStack .pop ();
335+ ExpressionEntry base = expressionStack .pop ();
357336 MethodCallExpressionEntry exp = new MethodCallExpressionEntry ();
358- if (pop instanceof FieldAccessEntry id ) {
337+ if (base instanceof FieldAccessEntry id ) {
359338 exp .setMethodName (id .fieldName ());
360339 expressionStack .push (exp );
361- Logger .output ("Method call: " + exp );
362- } else if (pop instanceof ChainedExpressionEntry chain ) {
363- exp .setMethodName (chain .chain .fieldName ());
340+ } else if (base instanceof ChainedExpressionEntry chain ) {
341+ exp .setMethodName (chain .chain .name ());
364342 chain .chain = exp ;
365343 expressionStack .push (chain );
366344 expressionStack .push (exp );
367- Logger .output ("Method call: " + exp );
368345 }
369346 }
370347
@@ -375,7 +352,6 @@ public void endMethodCall() {
375352 ExpressionEntry pop = expressionStack .pop ();
376353 if (pop != methodCall ) throw new RuntimeException ("Method call not on top of stack" );
377354 expressionStack .push (methodCall );
378- Logger .output ("Method call: " + methodCall );
379355 }, it -> it .arguments () != null );
380356 }
381357
@@ -394,7 +370,6 @@ public void expNewClass() {
394370 ExpressionEntry pop = expressionStack .pop ();
395371 if (pop != newClass ) throw new RuntimeException ("New class not on top of stack" );
396372 expressionStack .push (newClass );
397- Logger .output ("New class: " + newClass );
398373 }, it -> it .constructorArguments () != null );
399374 }
400375
0 commit comments