Skip to content

Commit c341c94

Browse files
committed
Merge branch 'refactor/tokenizer'
2 parents 85db57d + 2124127 commit c341c94

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+8103
-4340
lines changed

changes.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ Changed Behaviour
6666
decided to not fix the change to work as originally intended, and instead
6767
only allow type mixing if the array has explicitly been declared as
6868
`mixed`. See the documentation for details.
69+
- The `defined()` pseudo-function now returns `true` (while printing a
70+
warning) if applied to reserved words. The `#ifdef` and `#ifndef` directives
71+
also behave accordingly.
6972
- The dithering implementation has been modified, and may produce slightly
7073
different results for otherwise identical scenes.
7174
- The PGM (greyscale variant of PPM) output gamma handling now matches that
@@ -74,6 +77,10 @@ Changed Behaviour
7477
- Greyscale output no longer automatically forces bit depth to 16 bpc. To get
7578
16 bpp greyscale output, explicitly specify `Bits_Per_Color=16`.
7679
- Preview now reflects greyscale setting.
80+
- The `charset` global setting has been deprecated and may no longer work as
81+
expected. Input files conforming to ASCII, UTF-8, Latin-1 or Windows-1252
82+
encoding will instead be auto-detected, while other encodings are currently
83+
unsupported.
7784

7885
New Features
7986
------------

source/backend/configbackend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/// @parblock
1111
///
1212
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
13-
/// Copyright 1991-2018 Persistence of Vision Raytracer Pty. Ltd.
13+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
1414
///
1515
/// POV-Ray is free software: you can redistribute it and/or modify
1616
/// it under the terms of the GNU Affero General Public License as
@@ -94,7 +94,7 @@ static_assert(
9494
/// @note
9595
/// The macro is responsible for creating a sufficiently large result buffer, using @ref POV_MALLOC().
9696
/// @note
97-
/// The result must be a genuine UCS2 string. UCS4/Unicode characters outside the Base Multilingual Plane
97+
/// The result must be a genuine UCS2 string. UCS4/Unicode characters outside the Basic Multilingual Plane
9898
/// are not supported.
9999
///
100100
/// @param[in] ts Null-terminated byte sequence to convert.

source/backend/control/messagefactory.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ MessageFactory::~MessageFactory()
6363
{}
6464

6565
void MessageFactory::SendMessage(MessageClass mc, WarningLevel level, const char *text,
66-
const UCS2 *filename, POV_LONG line, POV_LONG column, POV_OFF_T offset)
66+
const UCS2String& filename, POV_LONG line, POV_LONG column, POV_OFF_T offset)
6767
{
6868
POVMSObject msg;
6969
unsigned int msgIdent;
7070

7171
(void)POVMSObject_New(&msg, kPOVObjectClass_ControlData);
7272

73-
if (filename != nullptr)
74-
(void)POVMSUtil_SetUCS2String(&msg, kPOVAttrib_FileName, filename);
73+
if (!filename.empty())
74+
(void)POVMSUtil_SetUCS2String(&msg, kPOVAttrib_FileName, filename.c_str());
7575
if (line != -1)
7676
(void)POVMSUtil_SetLong(&msg, kPOVAttrib_Line, line);
7777
if (column != -1)

source/backend/control/messagefactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class MessageFactory : public GenericMessenger
6363
RenderBackend::ViewId viewId;
6464

6565
virtual void SendMessage(MessageClass mc, WarningLevel level, const char *text,
66-
const UCS2 *filename = nullptr, POV_LONG line = -1, POV_LONG column = -1, POV_OFF_T offset = -1);
66+
const UCS2String& filename = u"", POV_LONG line = -1, POV_LONG column = -1, POV_OFF_T offset = -1) override;
6767
};
6868

6969
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
//******************************************************************************
2+
///
3+
/// @file backend/control/parsertask.cpp
4+
///
5+
/// This module implements the parser task in a multi-threaded architecture.
6+
///
7+
/// @copyright
8+
/// @parblock
9+
///
10+
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
11+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
12+
///
13+
/// POV-Ray is free software: you can redistribute it and/or modify
14+
/// it under the terms of the GNU Affero General Public License as
15+
/// published by the Free Software Foundation, either version 3 of the
16+
/// License, or (at your option) any later version.
17+
///
18+
/// POV-Ray is distributed in the hope that it will be useful,
19+
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
/// GNU Affero General Public License for more details.
22+
///
23+
/// You should have received a copy of the GNU Affero General Public License
24+
/// along with this program. If not, see <http://www.gnu.org/licenses/>.
25+
///
26+
/// ----------------------------------------------------------------------------
27+
///
28+
/// POV-Ray is based on the popular DKB raytracer version 2.12.
29+
/// DKBTrace was originally written by David K. Buck.
30+
/// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
31+
///
32+
/// @endparblock
33+
///
34+
//******************************************************************************
35+
36+
// Unit header file must be the first file included within POV-Ray *.cpp files (pulls in config)
37+
#include "backend/control/parsertask.h"
38+
39+
// C++ variants of C standard header files
40+
// C++ standard header files
41+
// Boost header files
42+
// POV-Ray header files (base module)
43+
// (none at the moment)
44+
45+
// POV-Ray header files (core module)
46+
#include "core/scene/tracethreaddata.h"
47+
48+
// POV-Ray header files (parser module)
49+
#include "parser/parser.h"
50+
51+
// POV-Ray header files (backend module)
52+
#include "backend/scene/backendscenedata.h"
53+
54+
// this must be the last file included
55+
#include "base/povdebug.h"
56+
57+
namespace pov
58+
{
59+
60+
using namespace pov_parser;
61+
62+
ParserTask::ParserTask(std::shared_ptr<BackendSceneData> sd, const ParserOptions& opts) :
63+
SceneTask(new TraceThreadData(sd, opts.randomSeed), boost::bind(&ParserTask::SendFatalError, this, _1), "Parse", sd),
64+
mpParser(nullptr),
65+
mpBackendSceneData(sd),
66+
mOptions(opts),
67+
mLastProgressElapsedTime(0)
68+
{}
69+
70+
void ParserTask::Run()
71+
{
72+
mpParser.reset(new Parser(mpBackendSceneData, mOptions, messageFactory, *this, *this, *reinterpret_cast<TraceThreadData *>(GetDataPtr())));
73+
mpParser->Run();
74+
}
75+
76+
void ParserTask::Stopped()
77+
{
78+
mpParser.reset();
79+
RenderBackend::SendSceneFailedResult(mpBackendSceneData->sceneId, kUserAbortErr, mpBackendSceneData->frontendAddress);
80+
}
81+
82+
void ParserTask::Finish()
83+
{
84+
if (mpParser != nullptr)
85+
{
86+
mpParser->GetParserDataPtr()->timeType = TraceThreadData::kParseTime;
87+
mpParser->GetParserDataPtr()->realTime = ConsumedRealTime();
88+
mpParser->GetParserDataPtr()->cpuTime = ConsumedCPUTime();
89+
mpParser->Finish();
90+
mpParser.reset();
91+
}
92+
}
93+
94+
void ParserTask::SendFatalError(Exception& e)
95+
{
96+
if (mpParser != nullptr)
97+
mpParser->SendFatalError(e);
98+
}
99+
100+
UCS2String ParserTask::FindFile(UCS2String parsedFileName, unsigned int fileType)
101+
{
102+
return mpBackendSceneData->FindFile(GetPOVMSContext(), parsedFileName, fileType);
103+
}
104+
105+
IStream* ParserTask::ReadFile(const UCS2String& parsedFileName, const UCS2String& foundFileName, unsigned int fileType)
106+
{
107+
return mpBackendSceneData->ReadFile(GetPOVMSContext(), parsedFileName, foundFileName, fileType);
108+
}
109+
110+
OStream* ParserTask::CreateFile(const UCS2String& parsedFileName, unsigned int fileType, bool append)
111+
{
112+
return mpBackendSceneData->CreateFile(GetPOVMSContext(), parsedFileName, fileType, append);
113+
}
114+
115+
void ParserTask::ReportProgress(POV_LONG tokenCount)
116+
{
117+
POV_LONG elapsedTime = ElapsedRealTime();
118+
if ((elapsedTime - mLastProgressElapsedTime) > kMinProgressReportInterval)
119+
{
120+
POVMS_Object obj(kPOVObjectClass_ParserProgress);
121+
obj.SetLong(kPOVAttrib_RealTime, elapsedTime);
122+
obj.SetLong(kPOVAttrib_CurrentTokenCount, tokenCount);
123+
RenderBackend::SendSceneOutput(mpBackendSceneData->sceneId, mpBackendSceneData->frontendAddress, kPOVMsgIdent_Progress, obj);
124+
Cooperate();
125+
mLastProgressElapsedTime = ElapsedRealTime();
126+
}
127+
}
128+
129+
} // end of namespace pov
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//******************************************************************************
2+
///
3+
/// @file backend/control/parsertask.h
4+
///
5+
/// Declarations related to the parser task.
6+
///
7+
/// @copyright
8+
/// @parblock
9+
///
10+
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
11+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
12+
///
13+
/// POV-Ray is free software: you can redistribute it and/or modify
14+
/// it under the terms of the GNU Affero General Public License as
15+
/// published by the Free Software Foundation, either version 3 of the
16+
/// License, or (at your option) any later version.
17+
///
18+
/// POV-Ray is distributed in the hope that it will be useful,
19+
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
/// GNU Affero General Public License for more details.
22+
///
23+
/// You should have received a copy of the GNU Affero General Public License
24+
/// along with this program. If not, see <http://www.gnu.org/licenses/>.
25+
///
26+
/// ----------------------------------------------------------------------------
27+
///
28+
/// POV-Ray is based on the popular DKB raytracer version 2.12.
29+
/// DKBTrace was originally written by David K. Buck.
30+
/// DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
31+
///
32+
/// @endparblock
33+
///
34+
//******************************************************************************
35+
36+
#ifndef POVRAY_BACKEND_PARSERTASK_H
37+
#define POVRAY_BACKEND_PARSERTASK_H
38+
39+
// Module config header file must be the first file included within POV-Ray unit header files
40+
#include "backend/configbackend.h"
41+
42+
// C++ variants of C standard header files
43+
// (none at the moment)
44+
45+
// C++ standard header files
46+
#include <memory>
47+
48+
// Boost header files
49+
// POV-Ray header files (base module)
50+
// POV-Ray header files (core module)
51+
// (none at the moment)
52+
53+
// POV-Ray header files (parser module)
54+
#include "parser/parser.h"
55+
56+
// POV-Ray header files (backend module)
57+
#include "backend/support/task.h"
58+
59+
namespace pov
60+
{
61+
62+
using namespace pov_base;
63+
using namespace pov;
64+
65+
class ParserTask : public SceneTask, public pov_parser::Parser::FileResolver, public pov_parser::Parser::ProgressReporter
66+
{
67+
public:
68+
69+
ParserTask(std::shared_ptr<BackendSceneData> sd, const pov_parser::ParserOptions& opts);
70+
71+
/// @name @ref SceneTask related.
72+
/// @{
73+
74+
virtual void Run() override;
75+
virtual void Stopped() override;
76+
virtual void Finish() override;
77+
void SendFatalError(Exception& e);
78+
79+
/// @}
80+
/// @name @ref Parser::FileResolver related.
81+
/// @{
82+
83+
virtual UCS2String FindFile(UCS2String parsedFileName, unsigned int fileType) override;
84+
virtual IStream* ReadFile(const UCS2String& parsedFileName, const UCS2String& foundFileName, unsigned int fileType) override;
85+
virtual OStream* CreateFile(const UCS2String& parsedFileName, unsigned int fileType, bool append) override;
86+
87+
/// @}
88+
/// @name @ref Parser::ProgressReporter related.
89+
/// @{
90+
91+
static constexpr auto kMinProgressReportInterval = 1000; /// Minimum delay between progress reports (in milliseconds).
92+
virtual void ReportProgress(POV_LONG tokenCount) override;
93+
94+
/// @}
95+
96+
private:
97+
98+
std::unique_ptr<pov_parser::Parser> mpParser;
99+
std::shared_ptr<BackendSceneData> mpBackendSceneData;
100+
pov_parser::ParserOptions mOptions;
101+
POV_LONG mLastProgressElapsedTime;
102+
};
103+
104+
} // end of namespace pov
105+
106+
#endif // POVRAY_BACKEND_PARSERTASK_H

source/backend/control/scene.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/// @parblock
99
///
1010
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
11-
/// Copyright 1991-2018 Persistence of Vision Raytracer Pty. Ltd.
11+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
1212
///
1313
/// POV-Ray is free software: you can redistribute it and/or modify
1414
/// it under the terms of the GNU Affero General Public License as
@@ -40,11 +40,12 @@
4040

4141
// frame.h must always be the first POV file included (pulls in platform config)
4242
#include "backend/frame.h"
43+
#include "backend/control/parsertask.h"
4344
#include "backend/control/scene.h"
4445

4546
#include "core/scene/tracethreaddata.h"
4647

47-
#include "parser/parser.h"
48+
#include "parser/parsertypes.h"
4849

4950
#include "backend/bounding/boundingtask.h"
5051
#include "backend/scene/view.h"
@@ -162,8 +163,8 @@ void Scene::StartParser(POVMS_Object& parseOptions)
162163
}
163164

164165
// do parsing
165-
sceneThreadData.push_back(dynamic_cast<TraceThreadData *>(parserTasks.AppendTask(new pov_parser::Parser(
166-
sceneData, bool(parseOptions.Exist(kPOVAttrib_Clock)), parseOptions.TryGetFloat(kPOVAttrib_Clock, 0.0), seed
166+
sceneThreadData.push_back(dynamic_cast<TraceThreadData *>(parserTasks.AppendTask(new pov_parser::ParserTask(
167+
sceneData, pov_parser::ParserOptions(bool(parseOptions.Exist(kPOVAttrib_Clock)), parseOptions.TryGetFloat(kPOVAttrib_Clock, 0.0), seed)
167168
))));
168169

169170
// wait for parsing

source/backend/frame.h

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/// @parblock
1212
///
1313
/// Persistence of Vision Ray Tracer ('POV-Ray') version 3.8.
14-
/// Copyright 1991-2018 Persistence of Vision Raytracer Pty. Ltd.
14+
/// Copyright 1991-2019 Persistence of Vision Raytracer Pty. Ltd.
1515
///
1616
/// POV-Ray is free software: you can redistribute it and/or modify
1717
/// it under the terms of the GNU Affero General Public License as
@@ -122,20 +122,6 @@ inline void Destroy_Float(DBL *x)
122122
delete x;
123123
}
124124

125-
/// @}
126-
///
127-
//******************************************************************************
128-
///
129-
/// @name Image Stuff
130-
/// @{
131-
132-
// Image types.
133-
134-
#define IMAGE_FILE GIF_FILE+SYS_FILE+TGA_FILE+PGM_FILE+PPM_FILE+PNG_FILE+JPEG_FILE+TIFF_FILE+BMP_FILE+EXR_FILE+HDR_FILE+IFF_FILE+GRAD_FILE
135-
#define NORMAL_FILE GIF_FILE+SYS_FILE+TGA_FILE+PGM_FILE+PPM_FILE+PNG_FILE+JPEG_FILE+TIFF_FILE+BMP_FILE+EXR_FILE+HDR_FILE+IFF_FILE+GRAD_FILE
136-
#define MATERIAL_FILE GIF_FILE+SYS_FILE+TGA_FILE+PGM_FILE+PPM_FILE+PNG_FILE+JPEG_FILE+TIFF_FILE+BMP_FILE+EXR_FILE+HDR_FILE+IFF_FILE+GRAD_FILE
137-
#define HF_FILE GIF_FILE+SYS_FILE+TGA_FILE+PGM_FILE+PPM_FILE+PNG_FILE+JPEG_FILE+TIFF_FILE+BMP_FILE+EXR_FILE+HDR_FILE+POT_FILE
138-
139125
/// @}
140126
///
141127
//******************************************************************************

0 commit comments

Comments
 (0)