Skip to content

Commit 6eb488e

Browse files
committed
Added global() pseudo-function to match the earlier local() pseudo-function.
1 parent de317f1 commit 6eb488e

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed

changes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ New Features
6666
assignments. The main purpose is to allow macros to return a set of values
6767
rather than just a single one.
6868

69+
- `local()` and `global()` pseudo-functions have been added to specifically
70+
refer to a local or global identifier, respectively.
71+
6972
- The macro syntax has been extended to allow for optional parameters.
7073

7174
- Light sources' distance-based fading can now be set to obey an inverse-power

source/base/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#define OFFICIAL_VERSION_STRING "3.7.1"
4646
#define OFFICIAL_VERSION_NUMBER 371
4747

48-
#define POV_RAY_PRERELEASE "alpha.8586719"
48+
#define POV_RAY_PRERELEASE "alpha.8596235"
4949

5050
#if (POV_RAY_IS_AUTOBUILD == 1) && ((POV_RAY_IS_OFFICIAL == 1) || (POV_RAY_IS_SEMI_OFFICIAL == 1))
5151
#ifdef POV_RAY_PRERELEASE

source/parser/parser.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ class Parser : public SceneTask
280280
bool R_Flag;
281281
};
282282

283+
enum IdentifierMode
284+
{
285+
kIdentifierModeUndefined,
286+
kIdentifierModeLocal,
287+
kIdentifierModeGlobal,
288+
};
289+
283290
// constructor
284291
Parser(shared_ptr<BackendSceneData> sd, bool useclock, DBL clock);
285292

@@ -547,7 +554,8 @@ class Parser : public SceneTask
547554

548555
CS_ENTRY *Cond_Stack;
549556
int CS_Index;
550-
bool Skipping, Inside_Ifdef, Inside_MacroDef, Inside_Local, Parsing_Directive;
557+
bool Skipping, Inside_Ifdef, Inside_MacroDef, Parsing_Directive;
558+
IdentifierMode Inside_IdentFn;
551559

552560
int Got_EOF; // WARNING: Changes to the use of this variable are very dangerous as it is used in many places assuming certain non-obvious side effects! [trf]
553561

source/parser/parser_tokenizer.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void Parser::pre_init_tokenizer ()
181181
Skipping = false;
182182
Inside_Ifdef = false;
183183
Inside_MacroDef = false;
184-
Inside_Local = false;
184+
Inside_IdentFn = kIdentifierModeUndefined;
185185
Parsing_Directive = false;
186186
Cond_Stack = NULL;
187187
Table_Index = -1;
@@ -627,7 +627,7 @@ void Parser::Get_Token ()
627627
case '_':
628628
Echo_ungetc(c);
629629
Read_Symbol ();
630-
if (!Parsing_Directive && (Token.Token_Id == LOCAL_TOKEN))
630+
if (!Parsing_Directive && (Inside_IdentFn == kIdentifierModeUndefined) && ((Token.Token_Id == LOCAL_TOKEN) || (Token.Token_Id == GLOBAL_TOKEN)))
631631
{
632632
if (!Skip_Spaces())
633633
Error("Expected '(', end of file reached instead", c2);
@@ -637,9 +637,9 @@ void Parser::Get_Token ()
637637
if (!Skip_Spaces())
638638
Error("Expected 'identifier', end of file reached instead", c2);
639639

640-
Inside_Local = true;
640+
Inside_IdentFn = (Token.Token_Id == LOCAL_TOKEN) ? kIdentifierModeLocal : kIdentifierModeGlobal;
641641
Read_Symbol();
642-
Inside_Local = false;
642+
Inside_IdentFn = kIdentifierModeUndefined;
643643

644644
if (!Skip_Spaces())
645645
Error("Expected ')', end of file reached instead", c2);
@@ -1305,7 +1305,8 @@ void Parser::Read_Symbol()
13051305
/* If its a reserved keyword, write it and return */
13061306
if ( (Temp_Entry = Find_Symbol(0,String)) != NULL)
13071307
{
1308-
if (!Inside_Ifdef || ((sceneData->EffectiveLanguageVersion() >= 3.71) && (Temp_Entry->Token_Number == LOCAL_TOKEN)))
1308+
if (!Inside_Ifdef || ((sceneData->EffectiveLanguageVersion() >= 3.71) &&
1309+
((Temp_Entry->Token_Number == LOCAL_TOKEN) || (Temp_Entry->Token_Number == GLOBAL_TOKEN))))
13091310
{
13101311
Write_Token (Temp_Entry->Token_Number, Token.Token_Col_No);
13111312
return;
@@ -1319,7 +1320,15 @@ void Parser::Read_Symbol()
13191320
if (!Skipping)
13201321
{
13211322
/* Search tables from newest to oldest */
1322-
for (Local_Index=Table_Index; Local_Index > 0; Local_Index--)
1323+
int firstIndex = Table_Index;
1324+
int lastIndex = 1; // index 0 is reserved for reserved words, not identifiers
1325+
if (Inside_IdentFn == kIdentifierModeGlobal)
1326+
// if inside "global()" pseudo-function, just test the global table
1327+
firstIndex = 1;
1328+
else if (Inside_IdentFn == kIdentifierModeLocal)
1329+
// if inside "local()" pseudo-function, just test the most local table
1330+
lastIndex = Table_Index;
1331+
for (Local_Index = firstIndex; Local_Index >= lastIndex; Local_Index--)
13231332
{
13241333
/* See if it's a previously declared identifier. */
13251334
if ((Temp_Entry = Find_Symbol(Local_Index,String)) != NULL)
@@ -1417,9 +1426,6 @@ void Parser::Read_Symbol()
14171426
Token.Table_Index = Local_Index;
14181427
return;
14191428
}
1420-
1421-
if (Inside_Local)
1422-
break;
14231429
}
14241430
}
14251431

@@ -2442,7 +2448,7 @@ void Parser::Parse_Directive(int After_Hash)
24422448
CASE4 (SLOPE_MAP_ID_TOKEN, NORMAL_MAP_ID_TOKEN, TEXTURE_MAP_ID_TOKEN, COLOUR_ID_TOKEN)
24432449
CASE4 (PIGMENT_MAP_ID_TOKEN, MEDIA_ID_TOKEN, STRING_ID_TOKEN, INTERIOR_ID_TOKEN)
24442450
CASE4 (DENSITY_ID_TOKEN, ARRAY_ID_TOKEN, DENSITY_MAP_ID_TOKEN, UV_ID_TOKEN)
2445-
CASE4 (VECTOR_4D_ID_TOKEN, RAINBOW_ID_TOKEN, FOG_ID_TOKEN, SKYSPHERE_ID_TOKEN)
2451+
CASE4 (VECTOR_4D_ID_TOKEN, RAINBOW_ID_TOKEN, FOG_ID_TOKEN, SKYSPHERE_ID_TOKEN)
24462452
CASE2 (MATERIAL_ID_TOKEN, SPLINE_ID_TOKEN)
24472453
Remove_Symbol (Token.Table_Index, Token.Token_String, Token.is_array_elem, Token.DataPtr, Token.Token_Id);
24482454
EXIT
@@ -3059,7 +3065,7 @@ Parser::Macro *Parser::Parse_Macro()
30593065
CASE4 (SLOPE_MAP_ID_TOKEN, NORMAL_MAP_ID_TOKEN, TEXTURE_MAP_ID_TOKEN, COLOUR_ID_TOKEN)
30603066
CASE4 (PIGMENT_MAP_ID_TOKEN, MEDIA_ID_TOKEN, STRING_ID_TOKEN, INTERIOR_ID_TOKEN)
30613067
CASE4 (DENSITY_ID_TOKEN, ARRAY_ID_TOKEN, DENSITY_MAP_ID_TOKEN, UV_ID_TOKEN)
3062-
CASE4 (VECTOR_4D_ID_TOKEN, RAINBOW_ID_TOKEN, FOG_ID_TOKEN, SKYSPHERE_ID_TOKEN)
3068+
CASE4 (VECTOR_4D_ID_TOKEN, RAINBOW_ID_TOKEN, FOG_ID_TOKEN, SKYSPHERE_ID_TOKEN)
30633069
CASE2 (MATERIAL_ID_TOKEN, SPLINE_ID_TOKEN)
30643070
newParameter.name = POV_STRDUP(Token.Token_String);
30653071
New->parameters.push_back(newParameter);
@@ -3968,7 +3974,7 @@ int Parser::Parse_For_Param (char** IdentifierPtr, DBL* EndPtr, DBL* StepPtr)
39683974
CASE4 (COLOUR_MAP_ID_TOKEN, TRANSFORM_ID_TOKEN, CAMERA_ID_TOKEN, PIGMENT_ID_TOKEN)
39693975
CASE4 (SLOPE_MAP_ID_TOKEN, NORMAL_MAP_ID_TOKEN, TEXTURE_MAP_ID_TOKEN, COLOUR_ID_TOKEN)
39703976
CASE4 (PIGMENT_MAP_ID_TOKEN, MEDIA_ID_TOKEN, STRING_ID_TOKEN, INTERIOR_ID_TOKEN)
3971-
CASE4 (DENSITY_MAP_ID_TOKEN, ARRAY_ID_TOKEN, DENSITY_ID_TOKEN, UV_ID_TOKEN)
3977+
CASE4 (DENSITY_ID_TOKEN, ARRAY_ID_TOKEN, DENSITY_MAP_ID_TOKEN, UV_ID_TOKEN)
39723978
CASE4 (VECTOR_4D_ID_TOKEN, RAINBOW_ID_TOKEN, FOG_ID_TOKEN, SKYSPHERE_ID_TOKEN)
39733979
CASE2 (MATERIAL_ID_TOKEN, SPLINE_ID_TOKEN)
39743980
if (Token.is_array_elem)

source/parser/reservedwords.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ enum TOKEN_IDS
226226
FRESNEL_TOKEN,
227227
GAMMA_TOKEN,
228228
GIF_TOKEN,
229+
GLOBAL_TOKEN,
229230
GRADIENT_TOKEN,
230231
GRANITE_TOKEN,
231232
HASH_TOKEN,
@@ -631,9 +632,6 @@ enum TOKEN_IDS
631632
EXR_TOKEN,
632633
HDR_TOKEN,
633634
DEBUG_TAG_TOKEN,
634-
#ifdef GLOBAL_PHOTONS
635-
GLOBAL_TOKEN,
636-
#endif
637635
AREA_ILLUMINATION_TOKEN, // JN2007: Full area lighting
638636
PREMULTIPLIED_TOKEN,
639637
MESH_CAMERA_TOKEN,

unix/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.7.1-alpha.8586719
1+
3.7.1-alpha.8596235

0 commit comments

Comments
 (0)