~oontvoo/+junk/test_hw

« back to all changes in this revision

Viewing changes to src/jminusminus/JClassDeclaration.java

  • Committer: vnguyen
  • Date: 2013-05-08 07:53:03 UTC
  • Revision ID: oontvoo@hotmail.com-20130508075303-ej3276l4f3lva9p8
supportĀ staticĀ block

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
    /** Static (class) fields of this class. */
48
48
    private List<JFieldDeclaration> staticFieldInitializations;
49
49
 
 
50
    /** static blocks */
 
51
    private final List<JStaticBlock> staticBlocks;
 
52
 
50
53
    /**
51
54
     * Construct an AST node for a class declaration given the line number, list
52
55
     * of class modifiers, name of the class, its super class type, and the
74
77
        hasExplicitConstructor = false;
75
78
        instanceFieldInitializations = new ArrayList<JFieldDeclaration>();
76
79
        staticFieldInitializations = new ArrayList<JFieldDeclaration>();
 
80
        staticBlocks = new ArrayList<JStaticBlock>();
77
81
        // TODO: Temp
78
82
        if (superTypes.size() > 1)
79
83
            superTypeIndex = 1;
226
230
                    instanceFieldInitializations.add(fieldDecl);
227
231
                }
228
232
            }
 
233
            else if (member instanceof JStaticBlock)
 
234
            {
 
235
                staticBlocks.add((JStaticBlock)member);
 
236
            }
229
237
        }
230
238
 
231
239
        // Finally, ensure that a non-abstract class has
268
276
        }
269
277
 
270
278
        // Generate a class initialization method?
271
 
        if (staticFieldInitializations.size() > 0) {
 
279
        if (staticFieldInitializations.size() > 0 || staticBlocks.size() > 0) {
272
280
            codegenClassInit(output);
273
281
        }
274
282
    }
375
383
            staticField.codegenInitializations(output);
376
384
        }
377
385
 
 
386
        for (JStaticBlock staticBlock : staticBlocks)
 
387
            staticBlock.codegen(output);
 
388
 
378
389
        // Return
379
390
        output.addNoArgInstruction(RETURN);
380
391
    }