diff --git a/src/blitzrc/compiler/parser.cpp b/src/blitzrc/compiler/parser.cpp index 758a6ee..4e5b98f 100644 --- a/src/blitzrc/compiler/parser.cpp +++ b/src/blitzrc/compiler/parser.cpp @@ -141,6 +141,15 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope ){ assertText = ""; } + // Inject Base Class + if (scope == STMTS_PROG && stmts->size() == 0 && toker->curr() != USESTRICTTYPING && !addedBaseClass ) { + toker->rollback(); + toker->inject("Type BaseClass\nEnd Type"); + toker->next(); + addedBaseClass = true; + } + + // Disable garbage collection if not in strict mode and strict is not set if (scope == STMTS_PROG && stmts->size() == 0 && toker->curr() != USESTRICTTYPING && !strictMode && collectingGarbage) { cout << "Included file is not Strict, disabling GC globally" << endl; @@ -713,6 +722,11 @@ DeclNode *Parser::parseStructDecl(DeclSeqNode* &funcs){ string className = toker->originalTextAt(toker->current_toke()); string ident=parseIdent(); string tag=parseTypeTag(); + + // If tag is not set, set it to baseclass + if (tag.empty() && ident != "baseclass") tag = "baseclass"; + if (className.empty() && ident == "baseclass") className = "BaseClass"; + while( toker->curr()=='\n' ) toker->next(); a_ptr fields( d_new DeclSeqNode() ); diff --git a/src/blitzrc/compiler/parser.h b/src/blitzrc/compiler/parser.h index 8ad6cf6..f51afba 100644 --- a/src/blitzrc/compiler/parser.h +++ b/src/blitzrc/compiler/parser.h @@ -26,6 +26,7 @@ class Parser{ bool test; bool strictMode = false; bool collectingGarbage = false; + bool addedBaseClass = false; DeclSeqNode *consts; DeclSeqNode *structs; diff --git a/tests/TypeTest.bb b/tests/TypeTest.bb index 730cbe4..87b751e 100644 --- a/tests/TypeTest.bb +++ b/tests/TypeTest.bb @@ -60,4 +60,14 @@ Test testConstructorArgs() Assert(testType1\setField = "testValue") ; You can still call new ConstructType without () to skip construction and set the Type up the old way +End Test + +Test testFindingClassName() + Local testType1.SecondType = new SecondType() + testType1\secondTestVar = "testValue" + Local typePointer@ = Ptr(testType1) + Local castedType.BaseClass = typePointer + Assert(castedType\className = "SecondType") + Local recastedType.SecondType = Recast.SecondType(castedType) + Assert(recastedType\secondTestVar = "testValue") End Test \ No newline at end of file