Skip to content

Commit 91c9449

Browse files
committed
Merge branch 'refactor/tokenizer' into autobuild/tokenizer
2 parents 9c2ce78 + ac88d0e commit 91c9449

File tree

9 files changed

+146
-215
lines changed

9 files changed

+146
-215
lines changed

source/base/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
/// where `N` is a serial number starting at 1 in each phase, `TIME` is the number of minutes
101101
/// since 2000-01-01 00:00, and `FEATURE` is an arbitrary alphanumeric moniker for a particular
102102
/// experimental feature.
103-
#define POV_RAY_PRERELEASE "x.tokenizer.9675110"
103+
#define POV_RAY_PRERELEASE "x.tokenizer.9684878"
104104

105105
#if defined(DOXYGEN) && !defined(POV_RAY_PRERELEASE)
106106
// Work around doxygen being unable to document undefined macros.

source/core/coretypes.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -610,18 +610,27 @@ inline void intrusive_ptr_release(GenericFunctionContextFactory* f) { if (!(--f-
610610
typedef intrusive_ptr<GenericFunctionContextFactory> GenericFunctionContextFactoryIPtr;
611611
typedef GenericFunctionContextFactory* GenericFunctionContextFactoryTPtr;
612612

613-
struct SourceInfo : MessageContext
613+
struct SourcePosition
614614
{
615-
UCS2String fileName;
616615
POV_LONG line;
617616
POV_LONG column;
618617
POV_OFF_T offset;
618+
SourcePosition() = default;
619+
SourcePosition(const SourcePosition&) = default;
620+
SourcePosition(POV_LONG l, POV_LONG c, POV_OFF_T o) : line(l), column(c), offset(o) {}
621+
};
622+
623+
struct SourceInfo : MessageContext
624+
{
625+
UCS2String fileName;
626+
SourcePosition position;
619627
SourceInfo() = default;
620-
SourceInfo(const MessageContext& o) : fileName(o.GetFileName()), line(o.GetLine()), column(o.GetColumn()), offset(o.GetOffset()) {}
628+
SourceInfo(const MessageContext& o) : fileName(o.GetFileName()), position(o.GetLine(), o.GetColumn(), o.GetOffset()) {}
629+
SourceInfo(const UCS2String& fn, SourcePosition& p) : fileName(fn), position(p) {}
621630
virtual UCS2String GetFileName() const override { return fileName; }
622-
virtual POV_LONG GetLine() const override { return line; }
623-
virtual POV_LONG GetColumn() const override { return column; }
624-
virtual POV_OFF_T GetOffset() const override { return offset; }
631+
virtual POV_LONG GetLine() const override { return position.line; }
632+
virtual POV_LONG GetColumn() const override { return position.column; }
633+
virtual POV_OFF_T GetOffset() const override { return position.offset; }
625634
};
626635

627636
struct CustomFunctionSourceInfo : SourceInfo

source/parser/fncode.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ FNCode::FNCode(Parser *pa, FunctionCode *f, bool is_local, const char *n)
124124
else
125125
function->sourceInfo.name = POV_STRDUP("");
126126
function->sourceInfo.fileName = parser->UCS2_strdup(parser->mToken.sourceFile->Name());
127-
function->sourceInfo.line = parser->mToken.raw.lexeme.position.line;
128-
function->sourceInfo.column = parser->mToken.raw.lexeme.position.column;
129-
function->sourceInfo.offset = parser->mToken.raw.lexeme.position.offset;
127+
function->sourceInfo.position = parser->mToken.raw.lexeme.position;
130128
function->flags = 0;
131129
function->private_copy_method = nullptr;
132130
function->private_destroy_method = nullptr;

source/parser/parser.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9014,7 +9014,7 @@ bool Parser::Parse_RValue (TokenId Previous, TokenId *NumberPtr, void **DataPtr,
90149014
void *Temp_Data;
90159015
POV_PARAM *New_Par;
90169016
bool Found=true;
9017-
int Temp_Count=3000000;
9017+
int Temp_Count=3000000; // TODO FIXME - magic value!
90189018
bool Old_Ok=Ok_To_Declare;
90199019
int Terms;
90209020
bool function_identifier;
@@ -9142,7 +9142,7 @@ bool Parser::Parse_RValue (TokenId Previous, TokenId *NumberPtr, void **DataPtr,
91429142
// get the number of tokens found
91439143
Temp_Count -= token_count;
91449144

9145-
// no tokens have been found or a fucntion call had no parameters in parenthesis
9145+
// no tokens have been found or a function call had no parameters in parenthesis
91469146
if (!((Temp_Count==-1) || (Temp_Count==TOKEN_OVERFLOW_RESET_COUNT)) && had_callable_identifier)
91479147
Error("Identifier expected, incomplete function call or spline call found instead.");
91489148

@@ -9457,7 +9457,6 @@ void Parser::Destroy_Ident_Data(void *Data, int Type)
94579457
{
94589458
int i;
94599459
POV_ARRAY *a;
9460-
DATA_FILE *Temp_File;
94619460

94629461
if(Data == nullptr)
94639462
return;
@@ -9563,10 +9562,7 @@ void Parser::Destroy_Ident_Data(void *Data, int Type)
95639562
POV_FREE(Data);
95649563
break;
95659564
case FILE_ID_TOKEN:
9566-
Temp_File = reinterpret_cast<DATA_FILE *>(Data);
9567-
Temp_File->In_File = nullptr;
9568-
Temp_File->Out_File = nullptr;
9569-
POV_FREE(Data);
9565+
delete reinterpret_cast<DATA_FILE *>(Data);
95709566
break;
95719567
case FUNCT_ID_TOKEN:
95729568
case VECTFUNCT_ID_TOKEN:

source/parser/parser.h

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,31 @@ class Parser : public SceneTask
305305

306306
struct DATA_FILE
307307
{
308-
shared_ptr<pov_base::ITextStream> In_File;
308+
shared_ptr<RawTokenizer> inTokenizer;
309+
RawToken inToken;
309310
shared_ptr<pov_base::OTextStream> Out_File;
311+
bool inUngetToken : 1;
310312
bool busyParsing : 1; ///< `true` if parsing a statement related to the file, `false` otherwise.
311-
bool R_Flag : 1;
313+
314+
bool ReadNextToken()
315+
{
316+
POV_PARSER_ASSERT(inTokenizer != nullptr);
317+
if (!inUngetToken && !inTokenizer->GetNextToken(inToken))
318+
{
319+
inToken.id = END_OF_FILE_TOKEN;
320+
return false;
321+
}
322+
inUngetToken = false;
323+
return true;
324+
}
325+
void UnReadToken()
326+
{
327+
POV_PARSER_ASSERT(!inUngetToken);
328+
if (inToken.id != END_OF_FILE_TOKEN)
329+
inUngetToken = true;
330+
}
331+
332+
DATA_FILE() : inUngetToken(false), busyParsing(false) {}
312333
};
313334

314335
// constructor
@@ -409,7 +430,7 @@ class Parser : public SceneTask
409430
void Release_Entry_Reference (SYM_TABLE *table, SYM_ENTRY *Entry);
410431
SYM_ENTRY *Destroy_Entry (SYM_ENTRY *Entry, bool destroyName);
411432
bool Parse_Ifdef_Param ();
412-
int Parse_For_Param (char**, DBL*, DBL*);
433+
int Parse_For_Param (UTF8String&, DBL*, DBL*);
413434

414435
// parstxtr.h/parstxtr.cpp
415436
TEXTURE *Parse_Texture (void);
@@ -471,7 +492,6 @@ class Parser : public SceneTask
471492
void Parse_Float_Param2 (DBL *Val1, DBL *Val2);
472493
void Init_Random_Generators (void);
473494
void Destroy_Random_Generators (void);
474-
DBL Parse_Signed_Float(void);
475495

476496
// function.h/function.cpp
477497
FUNCTION_PTR Parse_Function(void);
@@ -586,8 +606,6 @@ class Parser : public SceneTask
586606

587607
int line_count;
588608

589-
bool readingExternalFile;
590-
591609
vector<RawTokenizer::HotBookmark> maIncludeStack;
592610

593611
struct CS_ENTRY
@@ -598,11 +616,11 @@ class Parser : public SceneTask
598616
bool Macro_Same_Flag;
599617
bool Switch_Case_Ok_Flag;
600618
Macro *PMac;
601-
char* Loop_Identifier;
619+
UTF8String Loop_Identifier;
602620
DBL For_Loop_End;
603621
DBL For_Loop_Step;
604-
CS_ENTRY() : Cond_Type(BUSY_COND), PMac(nullptr), Loop_Identifier(nullptr) {}
605-
~CS_ENTRY() { POV_PARSER_ASSERT(Loop_Identifier == nullptr); }
622+
CS_ENTRY() : Cond_Type(BUSY_COND), PMac(nullptr) {}
623+
~CS_ENTRY() {}
606624
};
607625

608626
vector<CS_ENTRY> Cond_Stack;
@@ -738,6 +756,7 @@ class Parser : public SceneTask
738756
void Parse_Read(void);
739757
void Parse_Write(void);
740758
int Parse_Read_Value(DATA_FILE *User_File, TokenId Previous, TokenId *NumberPtr, void **DataPtr);
759+
bool Parse_Read_Float_Value(DBL& val, DATA_FILE *User_File);
741760
void Check_Macro_Vers(void);
742761
DBL Parse_Cond_Param(void);
743762
void Parse_Cond_Param2(DBL *V1,DBL *V2);

source/parser/parser_expressions.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3904,41 +3904,4 @@ void Parser::Destroy_Random_Generators()
39043904
Number_Of_Random_Generators = 0;
39053905
}
39063906

3907-
DBL Parser::Parse_Signed_Float(void)
3908-
{
3909-
DBL Sign=1.0;
3910-
DBL Val=0.0;
3911-
bool old_allow_id = Allow_Identifier_In_Call;
3912-
Allow_Identifier_In_Call = false;
3913-
3914-
EXPECT
3915-
CASE (PLUS_TOKEN)
3916-
END_CASE
3917-
3918-
CASE (DASH_TOKEN)
3919-
Sign=-1.0;
3920-
Get_Token();
3921-
// FALLTHROUGH
3922-
CASE (FLOAT_FUNCT_TOKEN)
3923-
if (mToken.Function_Id==FLOAT_TOKEN)
3924-
{
3925-
Val = Sign * mToken.Token_Float;
3926-
EXIT
3927-
}
3928-
else
3929-
{
3930-
Parse_Error(FLOAT_TOKEN);
3931-
}
3932-
END_CASE
3933-
3934-
OTHERWISE
3935-
Parse_Error(FLOAT_TOKEN);
3936-
END_CASE
3937-
END_EXPECT
3938-
3939-
Allow_Identifier_In_Call = old_allow_id;
3940-
3941-
return(Val);
3942-
}
3943-
39443907
}

0 commit comments

Comments
 (0)