llvm/llvm/tools/llvm-rc/ResourceFileWriter.cpp

//===-- ResourceFileWriter.cpp --------------------------------*- C++-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===---------------------------------------------------------------------===//
//
// This implements the visitor serializing resources to a .res stream.
//
//===---------------------------------------------------------------------===//

#include "ResourceFileWriter.h"
#include "llvm/Object/WindowsResource.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/EndianStream.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"

usingnamespacellvm::support;

// Take an expression returning llvm::Error and forward the error if it exists.
#define RETURN_IF_ERROR(Expr)

namespace llvm {
namespace rc {

// Class that employs RAII to save the current FileWriter object state
// and revert to it as soon as we leave the scope. This is useful if resources
// declare their own resource-local statements.
class ContextKeeper {};

static Error createError(const Twine &Message,
                         std::errc Type = std::errc::invalid_argument) {}

static Error checkNumberFits(uint32_t Number, size_t MaxBits,
                             const Twine &FieldName) {}

template <typename FitType>
static Error checkNumberFits(uint32_t Number, const Twine &FieldName) {}

// A similar function for signed integers.
template <typename FitType>
static Error checkSignedNumberFits(uint32_t Number, const Twine &FieldName,
                                   bool CanBeNegative) {}

static Error checkRCInt(RCInt Number, const Twine &FieldName) {}

static Error checkIntOrString(IntOrString Value, const Twine &FieldName) {}

static bool stripQuotes(StringRef &Str, bool &IsLongString) {}

static UTF16 cp1252ToUnicode(unsigned char C) {}

// Describes a way to handle '\0' characters when processing the string.
// rc.exe tool sometimes behaves in a weird way in postprocessing.
// If the string to be output is equivalent to a C-string (e.g. in MENU
// titles), string is (predictably) truncated after first 0-byte.
// When outputting a string table, the behavior is equivalent to appending
// '\0\0' at the end of the string, and then stripping the string
// before the first '\0\0' occurrence.
// Finally, when handling strings in user-defined resources, 0-bytes
// aren't stripped, nor do they terminate the string.

enum class NullHandlingMethod {};

// Parses an identifier or string and returns a processed version of it:
//   * Strip the string boundary quotes.
//   * Convert the input code page characters to UTF16.
//   * Squash "" to a single ".
//   * Replace the escape sequences with their processed version.
// For identifiers, this is no-op.
static Error processString(StringRef Str, NullHandlingMethod NullHandler,
                           bool &IsLongString, SmallVectorImpl<UTF16> &Result,
                           int CodePage) {}

uint64_t ResourceFileWriter::writeObject(const ArrayRef<uint8_t> Data) {}

Error ResourceFileWriter::writeCString(StringRef Str, bool WriteTerminator) {}

Error ResourceFileWriter::writeIdentifier(const IntOrString &Ident) {}

Error ResourceFileWriter::writeIntOrString(const IntOrString &Value) {}

void ResourceFileWriter::writeRCInt(RCInt Value) {}

Error ResourceFileWriter::appendFile(StringRef Filename) {}

void ResourceFileWriter::padStream(uint64_t Length) {}

Error ResourceFileWriter::handleError(Error Err, const RCResource *Res) {}

Error ResourceFileWriter::visitNullResource(const RCResource *Res) {}

Error ResourceFileWriter::visitAcceleratorsResource(const RCResource *Res) {}

Error ResourceFileWriter::visitBitmapResource(const RCResource *Res) {}

Error ResourceFileWriter::visitCursorResource(const RCResource *Res) {}

Error ResourceFileWriter::visitDialogResource(const RCResource *Res) {}

Error ResourceFileWriter::visitIconResource(const RCResource *Res) {}

Error ResourceFileWriter::visitCaptionStmt(const CaptionStmt *Stmt) {}

Error ResourceFileWriter::visitClassStmt(const ClassStmt *Stmt) {}

Error ResourceFileWriter::visitHTMLResource(const RCResource *Res) {}

Error ResourceFileWriter::visitMenuResource(const RCResource *Res) {}

Error ResourceFileWriter::visitMenuExResource(const RCResource *Res) {}

Error ResourceFileWriter::visitStringTableResource(const RCResource *Base) {}

Error ResourceFileWriter::visitUserDefinedResource(const RCResource *Res) {}

Error ResourceFileWriter::visitVersionInfoResource(const RCResource *Res) {}

Error ResourceFileWriter::visitCharacteristicsStmt(
    const CharacteristicsStmt *Stmt) {}

Error ResourceFileWriter::visitExStyleStmt(const ExStyleStmt *Stmt) {}

Error ResourceFileWriter::visitFontStmt(const FontStmt *Stmt) {}

Error ResourceFileWriter::visitLanguageStmt(const LanguageResource *Stmt) {}

Error ResourceFileWriter::visitStyleStmt(const StyleStmt *Stmt) {}

Error ResourceFileWriter::visitVersionStmt(const VersionStmt *Stmt) {}

Error ResourceFileWriter::visitMenuStmt(const MenuStmt *Stmt) {}

Error ResourceFileWriter::writeResource(
    const RCResource *Res,
    Error (ResourceFileWriter::*BodyWriter)(const RCResource *)) {}

// --- NullResource helpers. --- //

Error ResourceFileWriter::writeNullBody(const RCResource *) {}

// --- AcceleratorsResource helpers. --- //

Error ResourceFileWriter::writeSingleAccelerator(
    const AcceleratorsResource::Accelerator &Obj, bool IsLastItem) {}

Error ResourceFileWriter::writeAcceleratorsBody(const RCResource *Base) {}

// --- BitmapResource helpers. --- //

Error ResourceFileWriter::writeBitmapBody(const RCResource *Base) {}

// --- CursorResource and IconResource helpers. --- //

// ICONRESDIR structure. Describes a single icon in resource group.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/ms648016.aspx
struct IconResDir {};

// CURSORDIR structure. Describes a single cursor in resource group.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/ms648011(v=vs.85).aspx
struct CursorDir {};

// RESDIRENTRY structure, stripped from the last item. Stripping made
// for compatibility with RESDIR.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/ms648026(v=vs.85).aspx
struct ResourceDirEntryStart {};

// BITMAPINFOHEADER structure. Describes basic information about the bitmap
// being read.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx
struct BitmapInfoHeader {};

// Group icon directory header. Called ICONDIR in .ico/.cur files and
// NEWHEADER in .res files.
//
// Ref: msdn.microsoft.com/en-us/library/windows/desktop/ms648023(v=vs.85).aspx
struct GroupIconDir {};

enum class IconCursorGroupType {};

class SingleIconCursorResource : public RCResource {};

class IconCursorGroupResource : public RCResource {};

Error ResourceFileWriter::writeSingleIconOrCursorBody(const RCResource *Base) {}

Error ResourceFileWriter::writeIconOrCursorGroupBody(const RCResource *Base) {}

Error ResourceFileWriter::visitSingleIconOrCursor(const RCResource *Res) {}

Error ResourceFileWriter::visitIconOrCursorGroup(const RCResource *Res) {}

Error ResourceFileWriter::visitIconOrCursorResource(const RCResource *Base) {}

// --- DialogResource helpers. --- //

Error ResourceFileWriter::writeSingleDialogControl(const Control &Ctl,
                                                   bool IsExtended) {}

Error ResourceFileWriter::writeDialogBody(const RCResource *Base) {}

// --- HTMLResource helpers. --- //

Error ResourceFileWriter::writeHTMLBody(const RCResource *Base) {}

// --- MenuResource helpers. --- //

Error ResourceFileWriter::writeMenuDefinition(
    const std::unique_ptr<MenuDefinition> &Def, uint16_t Flags) {}

Error ResourceFileWriter::writeMenuExDefinition(
    const std::unique_ptr<MenuDefinition> &Def, uint16_t Flags) {}

Error ResourceFileWriter::writeMenuDefinitionList(
    const MenuDefinitionList &List) {}

Error ResourceFileWriter::writeMenuExDefinitionList(
    const MenuDefinitionList &List) {}

Error ResourceFileWriter::writeMenuBody(const RCResource *Base) {}

Error ResourceFileWriter::writeMenuExBody(const RCResource *Base) {}

// --- StringTableResource helpers. --- //

class BundleResource : public RCResource {};

Error ResourceFileWriter::visitStringTableBundle(const RCResource *Res) {}

Error ResourceFileWriter::insertStringIntoBundle(
    StringTableInfo::Bundle &Bundle, uint16_t StringID,
    const std::vector<StringRef> &String) {}

Error ResourceFileWriter::writeStringTableBundleBody(const RCResource *Base) {}

Error ResourceFileWriter::dumpAllStringTables() {}

// --- UserDefinedResource helpers. --- //

Error ResourceFileWriter::writeUserDefinedBody(const RCResource *Base) {}

// --- VersionInfoResourceResource helpers. --- //

Error ResourceFileWriter::writeVersionInfoBlock(const VersionInfoBlock &Blk) {}

Error ResourceFileWriter::writeVersionInfoValue(const VersionInfoValue &Val) {}

template <typename Ty>
static Ty getWithDefault(const StringMap<Ty> &Map, StringRef Key,
                         const Ty &Default) {}

Error ResourceFileWriter::writeVersionInfoBody(const RCResource *Base) {}

Expected<std::unique_ptr<MemoryBuffer>>
ResourceFileWriter::loadFile(StringRef File) const {}

} // namespace rc
} // namespace llvm