diff --git a/autotest/opp_array.cpp b/autotest/opp_array.cpp index cf105c0..b4d0984 100644 --- a/autotest/opp_array.cpp +++ b/autotest/opp_array.cpp @@ -3,8 +3,8 @@ int main(void) { - array a10; - array a20; + opp::array a10; + opp::array a20; for(int i=0; i<10; i++) a10[i] = i; diff --git a/autotest/opp_streamtest.cpp b/autotest/opp_streamtest.cpp index 1a9bfc5..940f106 100644 --- a/autotest/opp_streamtest.cpp +++ b/autotest/opp_streamtest.cpp @@ -4,6 +4,10 @@ #include #include +using opp::ostringstream; +using opp::istringstream; +using opp::endl; + float fdist(float a, float b) { float d = fabs(a - b); @@ -21,8 +25,6 @@ int main(void) os << i << endl; } - costream cout; - istringstream is(os.str()); int j = 0, k = 47; @@ -35,7 +37,7 @@ int main(void) assert(j == 40); #endif - os.str(string()); + os.str(opp::string()); #if 0 cout << "[" << os.str() << "]" << endl; diff --git a/autotest/opp_string.cpp b/autotest/opp_string.cpp index 8df38de..bf2b789 100644 --- a/autotest/opp_string.cpp +++ b/autotest/opp_string.cpp @@ -3,6 +3,8 @@ #include #include +using opp::string; + static const char HelloWorld[] = "Hello World"; static const char AndBeyond[] = "And Beyond"; static const char And[] = "And"; diff --git a/autotest/opp_vector.cpp b/autotest/opp_vector.cpp index 91ecca3..5e82699 100644 --- a/autotest/opp_vector.cpp +++ b/autotest/opp_vector.cpp @@ -3,7 +3,7 @@ int main(void) { - vector a; + opp::vector a; for(int i=0; i<10; i++) a.push_back(i); diff --git a/autotest/opp_vector_string.cpp b/autotest/opp_vector_string.cpp index ada3f16..96642be 100644 --- a/autotest/opp_vector_string.cpp +++ b/autotest/opp_vector_string.cpp @@ -4,6 +4,9 @@ #include #include +using opp::string; +using opp::vector; + string join(const vector & vs) { string sj; diff --git a/include/opp/algorithm.h b/include/opp/algorithm.h index b5586b2..56cc828 100644 --- a/include/opp/algorithm.h +++ b/include/opp/algorithm.h @@ -1,6 +1,8 @@ #ifndef OPP_ALGORITHM_H #define OPP_ALGORITHM_H +namespace opp { + template inline void swap(T & x, T & y) { @@ -33,5 +35,6 @@ void sort(T s, T e) } } +} #endif diff --git a/include/opp/array.h b/include/opp/array.h index 0956811..33d413b 100644 --- a/include/opp/array.h +++ b/include/opp/array.h @@ -1,6 +1,7 @@ #ifndef OPP_ARRAY_H #define OPP_ARRAY_H +namespace opp { template class array @@ -109,18 +110,8 @@ public: _data[i] = t; } }; - -#if 0 - void swap(array & a) - { - for(int i=0; i +namespace opp { + ifstream::ifstream(char fnum, char device, char channel, const string & name) { this->fnum = fnum; @@ -19,3 +21,4 @@ void ifstream::refill(void) mBufferFill = krnio_read(fnum, mBuffer, 32); } +} diff --git a/include/opp/ifstream.h b/include/opp/ifstream.h index 42d59cc..6a0394e 100644 --- a/include/opp/ifstream.h +++ b/include/opp/ifstream.h @@ -4,6 +4,7 @@ #include "iostream.h" #include "string.h" +namespace opp { class ifstream : public istream { @@ -17,7 +18,7 @@ protected: char fnum; }; - +} #pragma compile("ifstream.cpp") diff --git a/include/opp/iostream.cpp b/include/opp/iostream.cpp index 7df8992..5e730d2 100644 --- a/include/opp/iostream.cpp +++ b/include/opp/iostream.cpp @@ -2,6 +2,8 @@ #include #include +namespace opp { + ios::ios(void) : mFlags(0), mState(0), mWidth(0), mPrecision(6), mFill(' ') {} @@ -975,3 +977,5 @@ void cistream::refill(void) cistream cin; costream cout; + +} \ No newline at end of file diff --git a/include/opp/iostream.h b/include/opp/iostream.h index bca344f..42c0e89 100644 --- a/include/opp/iostream.h +++ b/include/opp/iostream.h @@ -3,6 +3,8 @@ #include +namespace opp { + class ios { public: @@ -205,6 +207,8 @@ ostream & operator<<(ostream & os, const iosetfill & s); extern cistream cin; extern costream cout; +} + #pragma compile("iostream.cpp"); #endif diff --git a/include/opp/move.h b/include/opp/move.h index 759781a..977fb64 100644 --- a/include/opp/move.h +++ b/include/opp/move.h @@ -1,10 +1,14 @@ #ifndef OPP_MOVE_H #define OPP_MOVE_H +namespace opp { + template T && move(T & m) { return (T &&)m; } +} + #endif diff --git a/include/opp/ofstream.cpp b/include/opp/ofstream.cpp index a447870..bbbbaaa 100644 --- a/include/opp/ofstream.cpp +++ b/include/opp/ofstream.cpp @@ -1,6 +1,8 @@ #include "ofstream.h" #include +namespace opp { + ofstream::ofstream(char fnum, char device, char channel, const string & name) { this->fnum = fnum; @@ -27,3 +29,4 @@ void ofstream::bput(char ch) } } +} diff --git a/include/opp/ofstream.h b/include/opp/ofstream.h index 65b47d9..6367fec 100644 --- a/include/opp/ofstream.h +++ b/include/opp/ofstream.h @@ -4,6 +4,7 @@ #include "iostream.h" #include "string.h" +namespace opp { class ofstream : public ostream { @@ -20,7 +21,7 @@ protected: char fnum; }; - +} #pragma compile("ofstream.cpp") diff --git a/include/opp/sstream.cpp b/include/opp/sstream.cpp index ca0ff9e..5954939 100644 --- a/include/opp/sstream.cpp +++ b/include/opp/sstream.cpp @@ -1,6 +1,8 @@ #include "sstream.h" #include +namespace opp { + ostringstream::ostringstream(void) { mBuffer = nullptr; @@ -80,3 +82,5 @@ void istringstream::refill(void) mBuffer[mBufferFill++] = mString[mSPos++]; } } + +} diff --git a/include/opp/sstream.h b/include/opp/sstream.h index 686f65a..8a0b4a7 100644 --- a/include/opp/sstream.h +++ b/include/opp/sstream.h @@ -3,6 +3,8 @@ #include "iostream.h" +namespace opp { + class ostringstream : public ostream { public: @@ -33,6 +35,7 @@ protected: char mSPos; }; +} #pragma compile("sstream.cpp") diff --git a/include/opp/string.cpp b/include/opp/string.cpp index a8476dd..cbfb8a5 100644 --- a/include/opp/string.cpp +++ b/include/opp/string.cpp @@ -2,6 +2,8 @@ #include #include +namespace opp { + static inline void smemcpy(char * dp, const char * sp, char s) { for(char i=0; i #include +namespace opp { + template class vector { @@ -237,4 +239,5 @@ void vector::erase(int at, int n) _data[_size].~T(); } +} #endif diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 255de13..7c5f71c 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -121,11 +121,14 @@ Declaration* DeclarationScope::Lookup(const Ident* ident, ScopeLevel limit) for (int i = 0; i < mUsed.Size(); i++) { - Declaration* dec = mUsed[i]->Lookup(ident, limit); + Declaration* dec = mUsed[i]->Lookup(ident, SLEVEL_NAMESPACE); if (dec) return dec; } + if (limit == SLEVEL_USING) + return nullptr; + return mParent ? mParent->Lookup(ident, limit) : nullptr; } diff --git a/oscar64/Declaration.h b/oscar64/Declaration.h index 084d7df..29a9fdb 100644 --- a/oscar64/Declaration.h +++ b/oscar64/Declaration.h @@ -118,6 +118,7 @@ class Declaration; enum ScopeLevel { SLEVEL_SCOPE, + SLEVEL_USING, SLEVEL_GLOBAL, SLEVEL_STATIC, SLEVEL_NAMESPACE, diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index 3b94c1d..bcb2c02 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -166,7 +166,7 @@ Declaration* Parser::ParseStructDeclaration(uint64 flags, DecType dt) { dec->mIdent = structName; dec->mQualIdent = mScope->Mangle(structName); - dec->mScope = new DeclarationScope(nullptr, SLEVEL_CLASS, structName); + dec->mScope = new DeclarationScope(nullptr, SLEVEL_CLASS, dec->mQualIdent); } if ((mCompilerOptions & COPT_CPLUSPLUS) && mScanner->mToken == TK_COLON) @@ -607,7 +607,7 @@ Declaration* Parser::ParseBaseTypeDeclaration(uint64 flags, bool qualified) if (dec && dec->mTemplate) dec = ParseTemplateExpansion(dec->mTemplate, nullptr); - while (qualified && dec && dec->mType == DT_TYPE_STRUCT && ConsumeTokenIf(TK_COLCOLON)) + while (qualified && dec && (dec->mType == DT_TYPE_STRUCT || dec->mType == DT_NAMESPACE) && ConsumeTokenIf(TK_COLCOLON)) { if (ExpectToken(TK_IDENT)) { @@ -3797,7 +3797,7 @@ Declaration* Parser::ParseDeclaration(Declaration * pdec, bool variable, bool ex { pdec = mCompilationUnits->mScope->Insert(ndec->mQualIdent, ndec); - if (ndec->mIdent == ndec->mQualIdent) + if (mScope->Mangle(ndec->mIdent) == ndec->mQualIdent) { Declaration* ldec = mScope->Insert(ndec->mIdent, pdec ? pdec : ndec); #if 0 @@ -4290,7 +4290,7 @@ Declaration* Parser::ParseQualIdent(void) { if (dec->mType == DT_NAMESPACE || dec->mType == DT_TYPE_STRUCT) { - Declaration* ndec = dec->mScope->Lookup(mScanner->mTokenIdent, SLEVEL_CLASS); + Declaration* ndec = dec->mScope->Lookup(mScanner->mTokenIdent, SLEVEL_USING); if (ndec) dec = ndec; @@ -7451,7 +7451,7 @@ Declaration* Parser::ParseTemplateExpansion(Declaration* tmpld, Declaration* exp { if (!(mdec->mFlags & DTF_DEFINED)) { - Declaration* mpdec = mScope->Lookup(tmpld->mScope->Mangle(mdec->mIdent)); + Declaration* mpdec = mCompilationUnits->mScope->Lookup(tmpld->mScope->Mangle(mdec->mIdent)); while (mpdec && !mdec->mBase->IsTemplateSameParams(mpdec->mBase, tdec)) mpdec = mpdec->mNext; if (mpdec && mpdec->mTemplate) @@ -7485,7 +7485,7 @@ void Parser::CompleteTemplateExpansion(Declaration* tmpld) { while (mdec) { - Declaration* mpdec = mScope->Lookup(mdec->mQualIdent); + Declaration* mpdec = mCompilationUnits->mScope->Lookup(mdec->mQualIdent); while (mpdec && !mpdec->IsSameParams(mdec->mParams)) mpdec = mpdec->mNext; if (mpdec && mpdec->mType == DT_TEMPLATE) @@ -7569,7 +7569,7 @@ void Parser::ParseTemplateDeclaration(void) if (mScanner->mToken == TK_IDENT) { bdec->mIdent = mScanner->mTokenIdent; - bdec->mQualIdent = mScope->Mangle(bdec->mIdent); + bdec->mQualIdent = mScope->Mangle(mScanner->mTokenIdent); while (mScanner->mToken != TK_SEMICOLON && mScanner->mToken != TK_OPEN_BRACE) mScanner->NextToken(); @@ -7631,7 +7631,12 @@ void Parser::ParseTemplateDeclaration(void) } } else + { mErrors->Error(bdec->mLocation, EERR_FUNCTION_TEMPLATE, "Function template expected"); + adec->mType = DT_TYPE_VOID; + tdec->mBase = adec; + adec->mTemplate = tdec; + } } tdec->mTokens = mScanner->CompleteRecord(); @@ -7640,14 +7645,15 @@ void Parser::ParseTemplateDeclaration(void) tdec->mQualIdent = tdec->mBase->mQualIdent; tdec->mScope->mName = tdec->mQualIdent; - Declaration * pdec = mScope->Insert(tdec->mQualIdent, tdec->mBase); + if (tdec->mQualIdent == mScope->Mangle(tdec->mIdent)) + mScope->Insert(tdec->mIdent, tdec->mBase); + + Declaration* pdec = mCompilationUnits->mScope->Insert(tdec->mQualIdent, tdec->mBase); if (pdec) { tdec->mBase->mNext = pdec->mNext; pdec->mNext = tdec->mBase; } - - mCompilationUnits->mScope->Insert(tdec->mQualIdent, tdec->mBase); } @@ -9180,8 +9186,11 @@ void Parser::ParseNamespace(void) if (!ns) { ns = new Declaration(mScanner->mLocation, DT_NAMESPACE); - mScope->Insert(ident, ns); ns->mScope = new DeclarationScope(mScope, SLEVEL_NAMESPACE, ident); + ns->mIdent = ident; + ns->mQualIdent = mScope->Mangle(ident); + + mScope->Insert(ident, ns); } mScanner->NextToken(); @@ -9198,6 +9207,11 @@ void Parser::ParseNamespace(void) } else if (mScanner->mToken == TK_SEMICOLON) mScanner->NextToken(); + else if (mScanner->mToken == TK_TEMPLATE) + { + mScanner->NextToken(); + ParseTemplateDeclaration(); + } else if (mScanner->mToken == TK_NAMESPACE) { mScanner->NextToken();