Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/blitzrc/compiler/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<DeclSeqNode> fields( d_new DeclSeqNode() );

Expand Down
1 change: 1 addition & 0 deletions src/blitzrc/compiler/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Parser{
bool test;
bool strictMode = false;
bool collectingGarbage = false;
bool addedBaseClass = false;

DeclSeqNode *consts;
DeclSeqNode *structs;
Expand Down
10 changes: 10 additions & 0 deletions tests/TypeTest.bb
Original file line number Diff line number Diff line change
Expand Up @@ -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