Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenerateC stuff #8

Draft
wants to merge 8 commits into
base: pr-radical-paradox-004
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/main/java/tripleo/elijah/stages/gen_c/AbstractGernNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package tripleo.elijah.stages.gen_c;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tripleo.elijah.stages.gen_fn.*;
import tripleo.elijah_fluffy.anno.ElLateInit;

class AbstractGernNode implements GernNode {
protected /*final*/ @ElLateInit GeneratedNode generatedNode;

public void setNode(final GeneratedNode aGeneratedNode) {
generatedNode = aGeneratedNode;
}

@Override
public @NotNull GeneratedNode carrier() {
return generatedNode;
}

@Override
public @Nullable GeneratedFunction asFunction() {
if (generatedNode instanceof GeneratedFunction)
return (GeneratedFunction) generatedNode;
return null;
}

@Override
public @Nullable GeneratedContainerNC asContainer() {
if (generatedNode instanceof GeneratedContainerNC)
return (GeneratedContainerNC) generatedNode;
return null;
}
@Override
public @Nullable GeneratedClass asClass() {
if (generatedNode instanceof GeneratedClass)
return (GeneratedClass) generatedNode;
return null;
}
@Override
public @Nullable GeneratedNamespace asNamespace() {
if (generatedNode instanceof GeneratedNamespace)
return (GeneratedNamespace) generatedNode;
return null;
}

@Override
public @Nullable GeneratedConstructor asConstructor() {
if (generatedNode instanceof GeneratedConstructor)
return (GeneratedConstructor) generatedNode;
return null;
}
}
662 changes: 295 additions & 367 deletions src/main/java/tripleo/elijah/stages/gen_c/GenerateC.java

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions src/main/java/tripleo/elijah/stages/gen_c/GernNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package tripleo.elijah.stages.gen_c;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tripleo.elijah.stages.gen_fn.*;
import tripleo.elijah.stages.gen_generic.GenerateResult;
import tripleo.elijah.stages.logging.ElLog;
import tripleo.elijah.work.WorkList;

public interface GernNode {
@NotNull
GeneratedNode carrier();

@Nullable
GeneratedFunction asFunction();

@Nullable
GeneratedContainerNC asContainer();

@Nullable
GeneratedClass asClass();

@Nullable
GeneratedNamespace asNamespace();

@Nullable
GeneratedConstructor asConstructor();

default boolean isAttached() {
return false;
}

default String identityString() {
throw new RuntimeException("identityString");
}

default void generateCodeForMethod(BaseGeneratedFunction aGf, GenerateResult aGr, WorkList aWorkList, GenerateC aGenerateC, ElLog aLOG) {
throw new RuntimeException("generateCodeForMethod");
}
}
15 changes: 15 additions & 0 deletions src/main/java/tripleo/elijah/stages/gen_c/GernNodeClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tripleo.elijah.stages.gen_c;

import tripleo.elijah.stages.gen_fn.GeneratedClass;
import tripleo.elijah.stages.gen_fn.GeneratedNode;

class GernNodeClass extends AbstractGernNode {
public GernNodeClass(final GeneratedNode aGeneratedNode) {
setNode(aGeneratedNode);
}

@Override
public GeneratedClass asClass() {
return (GeneratedClass) generatedNode;
}
}
45 changes: 45 additions & 0 deletions src/main/java/tripleo/elijah/stages/gen_c/GernNodeConstructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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) {
setNode(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);
}
}
62 changes: 62 additions & 0 deletions src/main/java/tripleo/elijah/stages/gen_c/GernNodeContainer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package tripleo.elijah.stages.gen_c;

import com.google.common.base.Preconditions;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import tripleo.elijah.stages.gen_fn.GeneratedClass;
import tripleo.elijah.stages.gen_fn.GeneratedContainerNC;
import tripleo.elijah.stages.gen_fn.GeneratedFunction;
import tripleo.elijah.stages.gen_fn.GeneratedNode;
import tripleo.elijah.stages.gen_generic.GenerateResult;
import tripleo.elijah.work.WorkManager;

import java.util.ArrayList;
import java.util.Collection;

class GernNodeContainer extends AbstractGernNode {
public GernNodeContainer(final GeneratedNode aGeneratedNode) {
setNode(aGeneratedNode);
}

@Override
public @Nullable GeneratedContainerNC asContainer() {
return (GeneratedContainerNC) generatedNode;
}

public void generateCode(final GenerateC aGenerateC, final GenerateResult aGenerateResult) {
final GeneratedContainerNC container = asContainer();
Preconditions.checkNotNull(container);
container.generateCode(aGenerateC, aGenerateResult);
}

GenerateResult generateCodeForFunctions(final WorkManager wm,
final @NotNull GeneratedContainerNC nc,
final GenerateC ggc,
final GenerateC aGenerateC) {
if (ggc != aGenerateC) {
throw new AssertionError();
}

final Collection<GeneratedFunction> values = nc.functionMap.values();
final @NotNull Collection<GeneratedNode> gn1 = new ArrayList<>();
for (GeneratedFunction node : values) {
//noinspection UseBulkOperation
gn1.add(node);
}
//noinspection UnnecessaryLocalVariable
final GenerateResult gr3 = aGenerateC.gern(gn1).generateCode(ggc, wm);
return gr3;
}

GenerateResult generateCodeForContainers(final WorkManager wm, final @NotNull GeneratedContainerNC nc, final GenerateC ggc, final GenerateC aGenerateC) {
final Collection<GeneratedClass> values = nc.classMap.values();
final @NotNull Collection<GeneratedNode> gn2 = new ArrayList<>();
for (GeneratedClass node : values) {
//noinspection UseBulkOperation
gn2.add(node);
}
//noinspection UnnecessaryLocalVariable
final GenerateResult gr4 = aGenerateC.gern(gn2).generateCode(ggc, wm);
return gr4;
}
}
55 changes: 55 additions & 0 deletions src/main/java/tripleo/elijah/stages/gen_c/GernNodeFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package tripleo.elijah.stages.gen_c;

import com.google.common.base.Preconditions;
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;

import java.util.Objects;

class GernNodeFunction extends AbstractGernNode {
public GernNodeFunction(final GeneratedNode aGeneratedNode) {
setNode(aGeneratedNode);
}

public GeneratedFunction asFunction() {
return (GeneratedFunction) generatedNode;
}

@Override
public boolean isAttached() {
final GeneratedFunction gf = asFunction();

Preconditions.checkNotNull((gf));

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

@Override
public String identityString() {
return Objects.requireNonNull(asFunction()).identityString();
}

@Override
public void generateCodeForMethod(final BaseGeneratedFunction aGf, final GenerateResult gr, final WorkList aWorkList, final GenerateC aGenerateC, final ElLog LOG) {
if (aGf instanceof GeneratedConstructor) {
LOG.err("Should not pass Constructor to GernNodeFunction::generateCodeForMethod " + aGf.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.generateCodeForMethod(this, gr, aWorkList);
}
}
16 changes: 16 additions & 0 deletions src/main/java/tripleo/elijah/stages/gen_c/GernNodeNamespace.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tripleo.elijah.stages.gen_c;

import org.jetbrains.annotations.Nullable;
import tripleo.elijah.stages.gen_fn.GeneratedNamespace;
import tripleo.elijah.stages.gen_fn.GeneratedNode;

class GernNodeNamespace extends AbstractGernNode {
public GernNodeNamespace(final GeneratedNode aGeneratedNode) {
setNode(aGeneratedNode);
}

@Override
public @Nullable GeneratedNamespace asNamespace() {
return (GeneratedNamespace) generatedNode;
}
}
8 changes: 8 additions & 0 deletions src/main/java/tripleo/elijah/stages/gen_c/Gerns.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package tripleo.elijah.stages.gen_c;

import tripleo.elijah.stages.gen_generic.GenerateResult;
import tripleo.elijah.work.WorkManager;

public interface Gerns extends Iterable<GernNode> {
GenerateResult generateCode(GenerateC aGgc, WorkManager aWm);
}
Loading
Loading