diff options
author | Rumou Duan <rduan@google.com> | 2017-02-16 22:14:32 +0000 |
---|---|---|
committer | Dmitry Lomov <dslomov@google.com> | 2017-02-17 14:52:59 +0000 |
commit | 77c6fc05b1344d5829c9a52170c9fb2043894fc0 (patch) | |
tree | 0ff0667657c9839ea6e1f443f7720e896308baf8 /src/main/java/com/google | |
parent | c680b75d10b46e03df9da665165a11d394c6998c (diff) |
Remove class member enum CppSource#Type and instead subclass CppSource with different implementations, one for each CppSource#Type.
Storing CppSource#Type in CppSource directly caused memory regression.
--
PiperOrigin-RevId: 147765701
MOS_MIGRATED_REVID=147765701
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CppSource.java | 91 |
1 files changed, 74 insertions, 17 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppSource.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppSource.java index bc6ff4b6ac..3546f42299 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppSource.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppSource.java @@ -14,15 +14,16 @@ package com.google.devtools.build.lib.rules.cpp; -import com.google.auto.value.AutoValue; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.cmdline.Label; import java.util.Map; /** A source file that is an input to a c++ compilation. */ -@AutoValue public abstract class CppSource { + private final Artifact source; + private final Label label; + private final Map<String, String> buildVariables; /** * Types of sources. @@ -33,37 +34,93 @@ public abstract class CppSource { CLIF_INPUT_PROTO, } - /** - * Creates a {@code CppSource}. - * - * @param source the actual source file - * @param label the label from which this source arises in the build graph - * @param buildVariables build variables that should be used specifically in the compilation - * of this source - * @param type type of the source file. - */ - static CppSource create(Artifact source, Label label, Map<String, String> buildVariables, - Type type) { - return new AutoValue_CppSource(source, label, buildVariables, type); + public CppSource(Artifact source, Label label, Map<String, String> buildVariables) { + this.source = source; + this.label = label; + this.buildVariables = buildVariables; } /** * Returns the actual source file. */ - abstract Artifact getSource(); + public Artifact getSource() { + return source; + } /** * Returns the label from which this source arises in the build graph. */ - abstract Label getLabel(); + public Label getLabel() { + return label; + } /** * Returns build variables to be used specifically in the compilation of this source. */ - abstract Map<String, String> getBuildVariables(); + public Map<String, String> getBuildVariables() { + return buildVariables; + } /** * Returns the type of this source. */ abstract Type getType(); + + private static class SourceCppSource extends CppSource { + + protected SourceCppSource(Artifact source, Label label, Map<String, String> buildVariables) { + super(source, label, buildVariables); + } + + @Override + public Type getType() { + return Type.SOURCE; + } + } + + private static class HeaderCppSource extends CppSource { + protected HeaderCppSource(Artifact source, Label label, Map<String, String> buildVariables) { + super(source, label, buildVariables); + } + + @Override + public Type getType() { + return Type.HEADER; + } + } + + private static class ClifProtoCppSource extends CppSource { + protected ClifProtoCppSource(Artifact source, Label label, Map<String, String> buildVariables) { + super(source, label, buildVariables); + } + + @Override + public Type getType() { + return Type.CLIF_INPUT_PROTO; + } + } + + + + /** + * Creates a {@code CppSource}. + * @param source the actual source file + * @param label the label from which this source arises in the build graph + * @param buildVariables build variables that should be used specifically in the compilation + * of this source + * @param type type of the source file. + */ + static CppSource create(Artifact source, Label label, Map<String, String> buildVariables, + Type type) { + switch (type) { + case SOURCE: + return new SourceCppSource(source, label, buildVariables); + case HEADER: + return new HeaderCppSource(source, label, buildVariables); + case CLIF_INPUT_PROTO: + return new ClifProtoCppSource(source, label, buildVariables); + default: + throw new IllegalStateException("Unhandled CppSource type: " + type); + } + } } |