Skip to content

Commit

Permalink
Move generateCodeForMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
Tripleo committed Sep 22, 2024
1 parent a0a6e3d commit 0571435
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
10 changes: 6 additions & 4 deletions src/main/java/tripleo/elijah/stages/gen_c/GenerateC.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,12 @@ private void generateCodeForMethod(final @NotNull GernNode gn,

private void generateCodeForConstructor(final GeneratedConstructor gf, final GenerateResult gr,
final WorkList aWorkList) {
if (gf.getFD() == null)
return;
final Generate_Code_For_Method gcfm = new Generate_Code_For_Method(this, LOG);
gcfm.generateCodeForConstructor(gf, gr, aWorkList);
final GernNode gern = gern(gf);
if (gern instanceof GernNodeConstructor) {
generateCodeForMethod(gern, gr, aWorkList);
} else {
throw new AssertionError();
}
}

String getTypeNameForGenClass(@NotNull final GeneratedNode aGenClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ public Generate_Code_For_Method(@NotNull final GenerateC aGenerateC, final ElLog
LOG = aLog; // use log from GenerateC
}

void generateCodeForMethod(final BaseGeneratedFunction gf, final GenerateResult gr, final WorkList aWorkList) {
void generateCodeForMethod(final GernNodeFunction gn, final GenerateResult gr, final WorkList aWorkList) {
final GeneratedFunction gf = gn.asFunction();
if (gf == null) {
throw new AssertionError();
}

final Generate_Method_Header gmh = new Generate_Method_Header(gf, gc, LOG);

tos.put_string_ln(String.format("%s {", gmh.header_string));
Expand Down Expand Up @@ -718,8 +723,11 @@ private void __action_DECL(final @NotNull Instruction instruction, final BufferT
LOG.err("8886 y is null (No typename specified)");
}

void generateCodeForConstructor(final @NotNull GeneratedConstructor gf, final GenerateResult gr,
final WorkList aWorkList) {
void generateCodeForConstructor(final GernNodeConstructor gn,
final GenerateResult gr,
final WorkList aWorkList) {
final @NotNull GeneratedConstructor gf = gn.asConstructor();

// TODO this code is only correct for classes and not meant for namespaces
final GeneratedClass x = (GeneratedClass) gf.getGenClass();
switch (x.getKlass().getType()) {
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/tripleo/elijah/stages/gen_c/GernNodeConstructor.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package tripleo.elijah.stages.gen_c;

import tripleo.elijah.stages.gen_fn.BaseGeneratedFunction;
import tripleo.elijah.stages.gen_fn.GeneratedConstructor;
import tripleo.elijah.stages.gen_fn.GeneratedFunction;
import tripleo.elijah.stages.gen_fn.GeneratedNode;
import tripleo.elijah.stages.gen_generic.GenerateResult;
import tripleo.elijah.stages.logging.ElLog;
import tripleo.elijah.work.WorkList;
import tripleo.elijah_fluffy.util.SimplePrintLoggerToRemoveSoon;

class GernNodeConstructor extends AbstractGernNode {
public GernNodeConstructor(final GeneratedNode aGeneratedNode) {
Expand All @@ -11,4 +17,29 @@ public GernNodeConstructor(final GeneratedNode aGeneratedNode) {
public GeneratedConstructor asConstructor() {
return (GeneratedConstructor) generatedNode;
}

@Override
public boolean isAttached() {
return generatedNode instanceof GeneratedConstructor;
}

@Override
public void generateCodeForMethod(final BaseGeneratedFunction gf0,
final GenerateResult gr,
final WorkList aWorkList,
final GenerateC aGenerateC,
final ElLog LOG) {
if (gf0 instanceof GeneratedFunction) {
LOG.err("Should not pass Function to GernNodeConstructor::generateCodeForMethod " + gf0.identityString());
return;
}

if (!this.isAttached()) {
SimplePrintLoggerToRemoveSoon.println_out("** Skipping generateCodeForMethod for " + this.identityString());
return;
}

final Generate_Code_For_Method gcfm = new Generate_Code_For_Method(aGenerateC, LOG);
gcfm.generateCodeForConstructor(this, gr, aWorkList);
}
}
12 changes: 4 additions & 8 deletions src/main/java/tripleo/elijah/stages/gen_c/GernNodeFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ public boolean isAttached() {

Preconditions.checkNotNull((gf));

// nice catch, idea
if (gf.getFD() == null)
return false;

return true;
// NOTE defensive
// noinspection ConstantValue
return gf.getFD() != null;
}

@Override
Expand All @@ -51,9 +49,7 @@ public void generateCodeForMethod(final BaseGeneratedFunction aGf, final Generat
return;
}

final GeneratedFunction gf = asFunction();
final Generate_Code_For_Method gcfm = new Generate_Code_For_Method(aGenerateC, LOG);

gcfm.generateCodeForMethod(gf, gr, aWorkList);
gcfm.generateCodeForMethod(this, gr, aWorkList);
}
}

0 comments on commit 0571435

Please sign in to comment.