brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 4c839a0 Raw
83 lines · c
1//===-- ResourceScriptToken.h -----------------------------------*- C++-*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===---------------------------------------------------------------------===//8//9// This declares the .rc script tokens and defines an interface for tokenizing10// the input data. The list of available tokens is located at11// ResourceScriptTokenList.def.12//13// Note that the tokenizer does not support preprocessor directives. The14// preprocessor should do its work on the .rc file before running llvm-rc.15//16// As for now, it is possible to parse ASCII files only (the behavior on17// UTF files might be undefined). However, it already consumes UTF-8 BOM, if18// there is any. Thus, ASCII-compatible UTF-8 files are tokenized correctly.19//20// Ref: msdn.microsoft.com/en-us/library/windows/desktop/aa380599(v=vs.85).aspx21//22//===---------------------------------------------------------------------===//23 24#ifndef LLVM_TOOLS_LLVMRC_RESOURCESCRIPTTOKEN_H25#define LLVM_TOOLS_LLVMRC_RESOURCESCRIPTTOKEN_H26 27#include "llvm/ADT/StringRef.h"28#include "llvm/Support/Error.h"29 30#include <cstdint>31#include <vector>32 33namespace llvm {34 35// A definition of a single resource script token. Each token has its kind36// (declared in ResourceScriptTokenList) and holds a value - a reference37// representation of the token.38// RCToken does not claim ownership on its value. A memory buffer containing39// the token value should be stored in a safe place and cannot be freed40// nor reallocated.41class RCToken {42public:43  enum class Kind {44#define TOKEN(Name) Name,45#define SHORT_TOKEN(Name, Ch) Name,46#include "ResourceScriptTokenList.def"47  };48 49  RCToken(RCToken::Kind RCTokenKind, StringRef Value);50 51  // Get an integer value of the integer token.52  uint32_t intValue() const;53  bool isLongInt() const;54 55  StringRef value() const;56  Kind kind() const;57 58  // Check if a token describes a low precedence binary operator.59  bool isLowPrecedenceBinaryOp() const;60 61  // Check if a token describes a high precedence binary operator.62  bool isHighPrecedenceBinaryOp() const;63 64private:65  Kind TokenKind;66  StringRef TokenValue;67};68 69// Tokenize Input.70// In case no error occurred, the return value contains71//   tokens in order they were in the input file.72// In case of any error, the return value contains73//   a textual representation of error.74//75// Tokens returned by this function hold only references to the parts76// of the Input. Memory buffer containing Input cannot be freed,77// modified or reallocated.78Expected<std::vector<RCToken>> tokenizeRC(StringRef Input, bool IsWindres);79 80} // namespace llvm81 82#endif83