Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ private void render(CppWriter writer) {
}

private void writeHeader(CppWriter writer, String serviceName) {
writer.write("/**")
.write(" * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.")
.write(" * SPDX-License-Identifier: Apache-2.0.")
.write(" */")
.write("")
.write("// Header compilation test for " + serviceName + " " + getTestType().toLowerCase() + " headers")
// Copyright/SPDX header is emitted by CppWriterDelegator when the file is created.
writer.write("// Header compilation test for " + serviceName + " " + getTestType().toLowerCase() + " headers")
.write("// " + getTestDescription())
.write("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@ public final void render(CppWriter writer) {
}

private void writeHeader(CppWriter writer) {
writer.write("/**")
.write(" * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.")
.write(" * SPDX-License-Identifier: Apache-2.0.")
.write(" */")
.write("")
.write("#pragma once");
// Copyright/SPDX header is emitted by CppWriterDelegator when the file is created.
writer.write("#pragma once");
}

private void writeNamespaceOpen(CppWriter writer, String serviceName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ public final void write() {
}

private void writeHeader(CppWriter writer) {
writer.write("/**")
.write(" * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.")
.write(" * SPDX-License-Identifier: Apache-2.0.")
.write(" */")
.write("")
.write("#pragma once");
// Copyright/SPDX header is emitted by CppWriterDelegator when the file is created.
writer.write("#pragma once");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ public CppWriter writeInclude(String header) {
write("#include <$L>", header);
return this;
}

/**
* Writes the standard Amazon copyright / SPDX license header that begins every
* generated file, followed by a blank line.
*/
public CppWriter writeCopyright() {
write("/**");
write(" * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.");
write(" * SPDX-License-Identifier: Apache-2.0.");
write(" */");
write("");
return this;
}

public CppWriter writeNamespaceOpen(String namespace) {
openBlock("namespace $L\n{", namespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
package com.amazonaws.util.awsclientsmithygenerator.generators;

import software.amazon.smithy.build.FileManifest;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;

public class CppWriterDelegator {
/** UTF-8 byte order mark (U+FEFF), prepended to every file to match C2J-generated output. */
private static final String UTF8_BOM = "\uFEFF";

private final FileManifest fileManifest;
private final Map<String, CppWriter> writers = new HashMap<>();

Expand All @@ -19,21 +21,18 @@ public CppWriterDelegator(FileManifest fileManifest) {
}

public void useFileWriter(String filename, Consumer<CppWriter> writerConsumer) {
CppWriter writer = writers.computeIfAbsent(filename, k -> new CppWriter());
// Every generated file begins with the standard copyright/SPDX header. Emit it once,
// when the writer is first created, so callers don't repeat it (and reopening a file
// for appending does not duplicate it).
CppWriter writer = writers.computeIfAbsent(filename, k -> new CppWriter().writeCopyright());
writerConsumer.accept(writer);
}

public void flushWriters() {
writers.forEach((filename, writer) -> {
try {
Path outputPath = fileManifest.getBaseDir().resolve(filename);
java.nio.file.Files.createDirectories(outputPath.getParent());
// Add UTF-8 BOM to match C2J-generated file format
String content = "" + writer.toString();
java.nio.file.Files.writeString(outputPath, content);
} catch (Exception e) {
throw new RuntimeException("Failed to write file: " + filename, e);
}
// Add UTF-8 BOM to match C2J-generated file format
String content = UTF8_BOM + writer.toString();
fileManifest.writeFile(filename, content);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static String capitalize(String str) {
}

// Match C2jModelToGeneratorModelTransformer.sanitizeServiceAbbreviation() exactly
private static String sanitizeServiceAbbreviation(String serviceAbbreviation) {
public static String sanitizeServiceAbbreviation(String serviceAbbreviation) {
return serviceAbbreviation.replace(" ", "").replace("-", "").replace("_", "").replace("Amazon", "").replace("AWS", "").replace("/", "");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ public static Optional<String> getDefaultValue(Shape shape) {
return Optional.empty();
}

/**
* Returns true if the shape maps to a C++ primitive type (int, long long, bool, double).
*
* @param shape the shape to check
* @return true if the shape is a primitive type
*/
public static boolean isPrimitive(Shape shape) {
return shape.isIntegerShape() || shape.isLongShape()
|| shape.isBooleanShape() || shape.isDoubleShape() || shape.isFloatShape();
}

/**
* Returns true if the shape type requires a "has been set" tracking flag.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ public static void renderHeader(CppWriter writer, Shape enumShape, String servic
String enumName = enumShape.getId().getName();
List<String> values = getEnumValues(enumShape);

writer.write("/**");
writer.write(" * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.");
writer.write(" * SPDX-License-Identifier: Apache-2.0.");
writer.write(" */");
writer.write("");
writer.write("#pragma once");
writer.write("#include <aws/core/utils/memory/stl/AWSString.h>");
writer.write("#include <aws/$1L/$2L_EXPORTS.h>",
Expand Down Expand Up @@ -107,11 +102,6 @@ public static void renderSource(CppWriter writer, Shape enumShape, String servic
List<String> values = getEnumValues(enumShape);
List<String> wireValues = getEnumWireValues(enumShape);

writer.write("/**");
writer.write(" * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.");
writer.write(" * SPDX-License-Identifier: Apache-2.0.");
writer.write(" */");
writer.write("");
writer.write("#include <aws/$1L/model/$2L.h>", projectName, enumName);
writer.write("#include <aws/core/utils/HashingUtils.h>");
writer.write("#include <aws/core/Globals.h>");
Expand Down Expand Up @@ -151,16 +141,18 @@ public static void renderSource(CppWriter writer, Shape enumShape, String servic
writer.write("");

// GetNameFor
writer.write(" Aws::String GetNameFor$1L($1L value) {", enumName);
writer.write(" switch (value) {");
writer.write(" Aws::String GetNameFor$1L($1L enumValue) {", enumName);
writer.write(" switch (enumValue) {");
writer.write(" case $1L::NOT_SET:", enumName);
writer.write(" return {};");
for (int i = 0; i < values.size(); i++) {
writer.write(" case $1L::$2L:", enumName, values.get(i));
writer.write(" return \"$L\";", wireValues.get(i));
}
writer.write(" default:");
writer.write(" EnumParseOverflowContainer* overflowContainer = Aws::GetEnumOverflowContainer();");
writer.write(" if (overflowContainer) {");
writer.write(" return overflowContainer->RetrieveOverflow(static_cast<int>(value));");
writer.write(" return overflowContainer->RetrieveOverflow(static_cast<int>(enumValue));");
writer.write(" }");
writer.write(" return {};");
writer.write(" }");
Expand Down Expand Up @@ -215,11 +207,11 @@ private static List<String> getEnumWireValues(Shape enumShape) {
"atomic_cancel", "atomic_commit", "atomic_noexcept", "auto",
"bitand", "bitor", "bool", "break", "case", "catch", "char",
"char16_t", "char32_t", "class", "compl", "concept", "const",
"constexpr", "const_cast", "continue", "co_await", "co_return", "co_yeild",
"constexpr", "const_cast", "continue", "co_await", "co_return", "co_yield",
"decltype", "default", "delete", "do", "double", "dynamic_cast",
"else", "enum", "explicit", "export", "extern", "false", "float",
"for", "friend", "goto", "if", "import", "inline", "int", "long",
"moduel", "mutable", "namespace", "new", "noexcept", "not", "not_eq",
"module", "mutable", "namespace", "new", "noexcept", "not", "not_eq",
"nullptr", "operator", "or", "or_eq", "private", "protected", "public",
"reflexpr", "register", "reinterpret_cast", "requires", "return",
"short", "signed", "sizeof", "static", "static_assert", "static_cast",
Expand Down
Loading
Loading