Browse Source

Fix '#include' inside '#ifdef' and add a default macro '__SQUILU__'

mingodad 7 years ago
parent
commit
c2881a0565
3 changed files with 13 additions and 0 deletions
  1. 8 0
      SquiLu/squirrel/sqcompiler.cpp
  2. 4 0
      SquiLu/squirrel/sqstate.cpp
  3. 1 0
      SquiLu/squirrel/sqstate.h

+ 8 - 0
SquiLu/squirrel/sqcompiler.cpp

@@ -546,6 +546,11 @@ public:
             //do not call Lex() since next token can try search for id defined in the include
             //and then go global instead of local, we'll call it after including
             id = Expect(TK_STRING_LITERAL, false);
+            if(_ifdef_exclude)
+            {
+                Lex();
+                return;
+            }
             //Warning(_SC("%s:%d:%d warning pragma include %s\n"),
             //        _stringval(_sourcename), line, column, _stringval(id));
 
@@ -589,12 +594,14 @@ public:
                 SQInteger saved_curdata = _lex.data->currdata;
                 SQInteger saved_prevtoken = _lex.data->prevtoken;
                 SQInteger saved_token = _token;
+                SQInteger saved__inside_ifdef = _inside_ifdef;
                 SQObjectPtr saved_source_name = _sourcename;
 
                 //set new source file
                 _fs->_sourcename = id;
                 _sourcename = id;
                 _lex.ResetReader(compilerReadFunc, fp, 1);
+                _inside_ifdef = 0;
 
                 //compile the include file
                 Lex();
@@ -619,6 +626,7 @@ public:
                 _lex._up = saved_up;
 
                 --_nested_includes_count;
+                _inside_ifdef = saved__inside_ifdef;
                 //done let's continue working
 
                 //Now we do the Lex() call skiped before compile the include file

+ 4 - 0
SquiLu/squirrel/sqstate.cpp

@@ -116,6 +116,9 @@ void SQSharedState::Init()
 	sq_new(_systemstrings,SQObjectPtrVec);
 	sq_new(_types,SQObjectPtrVec);
 	_defined_names = SQTable::Create(this,0);
+	_define_squilu = SQString::Create(this,_SC("__SQUILU__"));
+	SQObjectPtr value(true);
+	_table(_defined_names)->NewSlot(_define_squilu, value);
 	_metamethodsmap = SQTable::Create(this,MT_LAST-1);
 	//adding type strings to avoid memory trashing
 	//types names
@@ -176,6 +179,7 @@ SQSharedState::~SQSharedState()
     if(_releasehook) { _releasehook(_foreignptr,0,0); _releasehook = NULL; }
 	_constructoridx.Null();
 	_destructoridx.Null();
+	_define_squilu.Null();
 	_table(_registry)->Finalize();
 	_table(_consts)->Finalize();
 	_table(_metamethodsmap)->Finalize();

+ 1 - 0
SquiLu/squirrel/sqstate.h

@@ -93,6 +93,7 @@ public:
 	SQObjectPtr _consts;
 	SQObjectPtr _constructoridx;
 	SQObjectPtr _destructoridx;
+	SQObjectPtr _define_squilu;
 #ifndef NO_GARBAGE_COLLECTOR
 	SQCollectable *_gc_chain;
 #endif