1314564Sdim//===- lld/Core/Node.h - Input file class -----------------------*- C++ -*-===//
2280461Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6280461Sdim//
7280461Sdim//===----------------------------------------------------------------------===//
8280461Sdim///
9280461Sdim/// \file
10280461Sdim///
11280461Sdim/// The classes in this file represents inputs to the linker.
12280461Sdim///
13280461Sdim//===----------------------------------------------------------------------===//
14280461Sdim
15280461Sdim#ifndef LLD_CORE_NODE_H
16280461Sdim#define LLD_CORE_NODE_H
17280461Sdim
18280461Sdim#include "lld/Core/File.h"
19314564Sdim#include <algorithm>
20280461Sdim#include <memory>
21280461Sdim
22280461Sdimnamespace lld {
23280461Sdim
24280461Sdim// A Node represents a FileNode or other type of Node. In the latter case,
25280461Sdim// the node contains meta information about the input file list.
26280461Sdim// Currently only GroupEnd node is defined as a meta node.
27280461Sdimclass Node {
28280461Sdimpublic:
29280461Sdim  enum class Kind { File, GroupEnd };
30314564Sdim
31280461Sdim  explicit Node(Kind type) : _kind(type) {}
32314564Sdim  virtual ~Node() = default;
33314564Sdim
34280461Sdim  virtual Kind kind() const { return _kind; }
35280461Sdim
36280461Sdimprivate:
37280461Sdim  Kind _kind;
38280461Sdim};
39280461Sdim
40280461Sdim// This is a marker for --end-group. getSize() returns the number of
41280461Sdim// files between the corresponding --start-group and this marker.
42280461Sdimclass GroupEnd : public Node {
43280461Sdimpublic:
44280461Sdim  explicit GroupEnd(int size) : Node(Kind::GroupEnd), _size(size) {}
45280461Sdim
46280461Sdim  int getSize() const { return _size; }
47280461Sdim
48280461Sdim  static bool classof(const Node *a) {
49280461Sdim    return a->kind() == Kind::GroupEnd;
50280461Sdim  }
51280461Sdim
52280461Sdimprivate:
53280461Sdim  int _size;
54280461Sdim};
55280461Sdim
56280461Sdim// A container of File.
57280461Sdimclass FileNode : public Node {
58280461Sdimpublic:
59280461Sdim  explicit FileNode(std::unique_ptr<File> f)
60303239Sdim      : Node(Node::Kind::File), _file(std::move(f)) {}
61280461Sdim
62280461Sdim  static bool classof(const Node *a) {
63280461Sdim    return a->kind() == Node::Kind::File;
64280461Sdim  }
65280461Sdim
66280461Sdim  File *getFile() { return _file.get(); }
67280461Sdim
68280461Sdimprotected:
69280461Sdim  std::unique_ptr<File> _file;
70280461Sdim};
71280461Sdim
72314564Sdim} // end namespace lld
73280461Sdim
74280461Sdim#endif // LLD_CORE_NODE_H
75