CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
SourceCode.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "AST/SourceArea.hpp"
11
13
17
18#include <istream>
19#include <memory>
20
22
23 // Source code stream class.
24 class SourceCode {
25 protected:
30
31 protected:
32 SourceCode() = default;
33
34 public:
36
37 // Returns true if this is a valid source code stream.
38 [[nodiscard]] bool isValid() const;
39
40 // Returns the next character from the source.
41 [[nodiscard]] char next();
42
43 // Fetches the line with the marker string of the specified source position.
44 bool fetchLineMarker(const SourceArea& area, String& line, String& marker);
45
46 // Sets the new source origin for the current source position (see "Pos()").
47 void nextSourceOrigin(const String& filename, Int32 lineOffset);
48
49 // Ignores the current character.
50 inline void ignore() { (void)next(); }
51
52 // Returns the current source position.
53 [[nodiscard]] inline const SourcePosition& getPosition() const { return mPosition; }
54
55 // Returns the current source line.
56 [[nodiscard]] inline const String& getLine() const { return mCurrentLine; }
57
58 // Returns the filename of the current source position (see SourcePosition::GetOrigin).
60
61 protected:
62 // Returns the line (if it has already been read) by the zero-based line index.
63 [[nodiscard]] String getLine(std::size_t lineIndex) const;
64 };
65
67
68} // namespace CeresEngine::ShaderCompiler
Definition SourceArea.hpp:20
Definition SourceCode.hpp:24
SPtr< std::istream > mStream
Definition SourceCode.hpp:26
String mCurrentLine
Definition SourceCode.hpp:27
void nextSourceOrigin(const String &filename, Int32 lineOffset)
const String & getLine() const
Definition SourceCode.hpp:56
String getLine(std::size_t lineIndex) const
Vector< String > mLines
Definition SourceCode.hpp:28
void ignore()
Definition SourceCode.hpp:50
bool fetchLineMarker(const SourceArea &area, String &line, String &marker)
SourcePosition mPosition
Definition SourceCode.hpp:29
SourceCode(const SPtr< std::istream > &stream)
const SourcePosition & getPosition() const
Definition SourceCode.hpp:53
Definition SourcePosition.hpp:30
Definition AST.hpp:33
SPtr< SourceCode > SourceCodePtr
Definition SourceCode.hpp:66
std::shared_ptr< T > SPtr
SPtr is a smart pointer that retains shared ownership of an object through a pointer.
Definition SmartPtr.hpp:37
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
std::int32_t Int32
Definition DataTypes.hpp:21
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25