Changeset View
Changeset View
Standalone View
Standalone View
kdev-pg/kdev-pg-code-gen.cpp
Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 92 | { | |||
---|---|---|---|---|---|
96 | 96 | | |||
97 | QString capSymbolName = node->mSymbol->mCapitalizedName; | 97 | QString capSymbolName = node->mSymbol->mCapitalizedName; | ||
98 | 98 | | |||
99 | if (globalSystem.generateAst) | 99 | if (globalSystem.generateAst) | ||
100 | { | 100 | { | ||
101 | sprintf(__var, "__node_%d", __id); | 101 | sprintf(__var, "__node_%d", __id); | ||
102 | ++__id; | 102 | ++__id; | ||
103 | 103 | | |||
104 | out << capSymbolName << "Ast *" << __var << " = 0;" << endl | 104 | out << capSymbolName << "Ast *" << __var << " = nullptr;" << endl | ||
105 | << "if (!parse" << capSymbolName << "(&" << __var; | 105 | << "if (!parse" << capSymbolName << "(&" << __var; | ||
106 | 106 | | |||
107 | if (!node->mArguments.isEmpty()) | 107 | if (!node->mArguments.isEmpty()) | ||
108 | out << ", " << node->mArguments; | 108 | out << ", " << node->mArguments; | ||
109 | 109 | | |||
110 | out << "))" << endl; | 110 | out << "))" << endl; | ||
111 | } | 111 | } | ||
112 | else | 112 | else | ||
▲ Show 20 Lines • Show All 468 Lines • ▼ Show 20 Line(s) | 580 | if(printElse) | |||
581 | out << "else "; | 581 | out << "else "; | ||
582 | printElse = true; | 582 | printElse = true; | ||
583 | out << "if("; | 583 | out << "if("; | ||
584 | generateTestCondition(i->op.mTok, out); | 584 | generateTestCondition(i->op.mTok, out); | ||
585 | if(i->op.mCond.size() != 0) | 585 | if(i->op.mCond.size() != 0) | ||
586 | out << " && " << i->op.mCond; | 586 | out << " && " << i->op.mCond; | ||
587 | out << ") { const unsigned int priority = " << i->priority << ";"; | 587 | out << ") { const unsigned int priority = " << i->priority << ";"; | ||
588 | out << i->op.mCode; | 588 | out << i->op.mCode; | ||
589 | out << "AstNode *last = 0; bool br = false;"; | 589 | out << "AstNode *last = nullptr; bool br = false;"; | ||
590 | out << "while(priority < opStack.last().p + " << i->left << ") {"; | 590 | out << "while(priority < opStack.last().p + " << i->left << ") {"; | ||
591 | out << "if(opStack.size() == 1) {" | 591 | out << "if(opStack.size() == 1) {" | ||
592 | "if(last)\n" | 592 | "if(last)\n" | ||
593 | "opStack.last().n->endToken = last->endToken;" | 593 | "opStack.last().n->endToken = last->endToken;" | ||
594 | "last = opStack.last().n;" | 594 | "last = opStack.last().n;" | ||
595 | "opStack.pop_back();" | 595 | "opStack.pop_back();" | ||
596 | "opStack.push_front(OperatorStackItem((*yynode) = create<Postfix"<< nodeType << ">(last), -2));" | 596 | "opStack.push_front(OperatorStackItem((*yynode) = create<Postfix"<< nodeType << ">(last), -2));" | ||
597 | "(*yynode)->endToken = last->endToken + 1;" | 597 | "(*yynode)->endToken = last->endToken + 1;" | ||
Show All 17 Lines | 614 | if(printElse) | |||
615 | out << "else "; | 615 | out << "else "; | ||
616 | printElse = true; | 616 | printElse = true; | ||
617 | out << "if("; | 617 | out << "if("; | ||
618 | generateTestCondition(i->op.mTok, out); | 618 | generateTestCondition(i->op.mTok, out); | ||
619 | if(i->op.mCond.size() != 0) | 619 | if(i->op.mCond.size() != 0) | ||
620 | out << " && " << i->op.mCond; | 620 | out << " && " << i->op.mCond; | ||
621 | out << ") { const unsigned int priority = " << i->priority << ";"; | 621 | out << ") { const unsigned int priority = " << i->priority << ";"; | ||
622 | out << i->op.mCode; | 622 | out << i->op.mCode; | ||
623 | out << "AstNode *last = 0; bool br = false;"; | 623 | out << "AstNode *last = nullptr; bool br = false;"; | ||
624 | out << "while(priority < opStack.last().p + " << i->left << ") {"; | 624 | out << "while(priority < opStack.last().p + " << i->left << ") {"; | ||
625 | out << "if(opStack.size() == 1) {" | 625 | out << "if(opStack.size() == 1) {" | ||
626 | "if(last)\n" | 626 | "if(last)\n" | ||
627 | "opStack.last().n->endToken = last->endToken;" | 627 | "opStack.last().n->endToken = last->endToken;" | ||
628 | "last = opStack.last().n;\n" | 628 | "last = opStack.last().n;\n" | ||
629 | "opStack.pop_back();" | 629 | "opStack.pop_back();" | ||
630 | "opStack.push_front(OperatorStackItem((*yynode) = create<Binary" << nodeType << ">(last), priority));" | 630 | "opStack.push_front(OperatorStackItem((*yynode) = create<Binary" << nodeType << ">(last), priority));" | ||
631 | "(*yynode)->startToken = last->startToken;" | 631 | "(*yynode)->startToken = last->startToken;" | ||
Show All 23 Lines | 654 | if(printElse) | |||
655 | out << "else "; | 655 | out << "else "; | ||
656 | printElse = true; | 656 | printElse = true; | ||
657 | out << "if("; | 657 | out << "if("; | ||
658 | generateTestCondition(i->first.mTok, out); | 658 | generateTestCondition(i->first.mTok, out); | ||
659 | if(i->first.mCond.size() != 0) | 659 | if(i->first.mCond.size() != 0) | ||
660 | out << " && " << i->first.mCond; | 660 | out << " && " << i->first.mCond; | ||
661 | out << ") { const unsigned int priority = " << i->priority << ";"; | 661 | out << ") { const unsigned int priority = " << i->priority << ";"; | ||
662 | out << i->first.mCode; | 662 | out << i->first.mCode; | ||
663 | out << "AstNode *last = 0; bool br = false;"; | 663 | out << "AstNode *last = nullptr; bool br = false;"; | ||
664 | out << "while(priority < opStack.last().p + " << i->left << ") {"; | 664 | out << "while(priority < opStack.last().p + " << i->left << ") {"; | ||
665 | out << "if(opStack.size() == 1) {" | 665 | out << "if(opStack.size() == 1) {" | ||
666 | "if(last)\n" | 666 | "if(last)\n" | ||
667 | "opStack.last().n->endToken = last->endToken;" | 667 | "opStack.last().n->endToken = last->endToken;" | ||
668 | "last = opStack.last().n;\n" | 668 | "last = opStack.last().n;\n" | ||
669 | "opStack.pop_back();" | 669 | "opStack.pop_back();" | ||
670 | "opStack.push_front(OperatorStackItem((*yynode) = create<Ternary" << nodeType << ">(last), priority));" | 670 | "opStack.push_front(OperatorStackItem((*yynode) = create<Ternary" << nodeType << ">(last), priority));" | ||
671 | "(*yynode)->startToken = last->startToken;" | 671 | "(*yynode)->startToken = last->startToken;" | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 706 | { | |||
714 | out << ") { const unsigned int priority = " << i->priority << ";"; | 714 | out << ") { const unsigned int priority = " << i->priority << ";"; | ||
715 | out << i->op.mCode | 715 | out << i->op.mCode | ||
716 | << "Prefix" << nodeType << " *node = create<Prefix" << nodeType << ">();" | 716 | << "Prefix" << nodeType << " *node = create<Prefix" << nodeType << ">();" | ||
717 | "if(opStack.empty())\n" | 717 | "if(opStack.empty())\n" | ||
718 | "(*yynode) = node;" | 718 | "(*yynode) = node;" | ||
719 | "else" | 719 | "else" | ||
720 | "{\n" | 720 | "{\n" | ||
721 | "void *last = opStack.last().n;" | 721 | "void *last = opStack.last().n;" | ||
722 | "if(reinterpret_cast<Prefix" << nodeType << "*>(last)->first == 0)\n" | 722 | "if(reinterpret_cast<Prefix" << nodeType << "*>(last)->first == nullptr)\n" | ||
723 | "reinterpret_cast<Prefix" << nodeType << "*>(last)->first = node;" | 723 | "reinterpret_cast<Prefix" << nodeType << "*>(last)->first = node;" | ||
724 | "else if(reinterpret_cast<Binary" << nodeType << "*>(last)->second == 0)\n" | 724 | "else if(reinterpret_cast<Binary" << nodeType << "*>(last)->second == nullptr)\n" | ||
725 | "reinterpret_cast<Binary" << nodeType << "*>(last)->second = node;" | 725 | "reinterpret_cast<Binary" << nodeType << "*>(last)->second = node;" | ||
726 | "else\n" | 726 | "else\n" | ||
727 | "reinterpret_cast<Ternary" << nodeType << "*>(last)->third = node;" | 727 | "reinterpret_cast<Ternary" << nodeType << "*>(last)->third = node;" | ||
728 | "}" | 728 | "}" | ||
729 | "opStack.push_back(OperatorStackItem(node, priority));" | 729 | "opStack.push_back(OperatorStackItem(node, priority));" | ||
730 | "node->startToken = tokenStream->index() - 1;" | 730 | "node->startToken = tokenStream->index() - 1;" | ||
731 | "yylex();" | 731 | "yylex();" | ||
732 | "}" << endl; | 732 | "}" << endl; | ||
Show All 22 Lines | 752 | out << ")) {" | |||
755 | "--" << __var << "->startToken;" | 755 | "--" << __var << "->startToken;" | ||
756 | "++" << __var << "->endToken;" | 756 | "++" << __var << "->endToken;" | ||
757 | "yylex();"; | 757 | "yylex();"; | ||
758 | #define PUSH_UNARY \ | 758 | #define PUSH_UNARY \ | ||
759 | out << "\ | 759 | out << "\ | ||
760 | if(!opStack.isEmpty())\ | 760 | if(!opStack.isEmpty())\ | ||
761 | {\ | 761 | {\ | ||
762 | void *last = opStack.last().n;\ | 762 | void *last = opStack.last().n;\ | ||
763 | if(reinterpret_cast<Prefix" << nodeType << "*>(last)->first == 0)\n\ | 763 | if(reinterpret_cast<Prefix" << nodeType << "*>(last)->first == nullptr)\n\ | ||
764 | reinterpret_cast<Prefix" << nodeType << "*>(last)->first = " << __var << ";" << endl; \ | 764 | reinterpret_cast<Prefix" << nodeType << "*>(last)->first = " << __var << ";" << endl; \ | ||
765 | out << "else if(reinterpret_cast<Binary" << nodeType << "*>(last)->second == 0)\n\ | 765 | out << "else if(reinterpret_cast<Binary" << nodeType << "*>(last)->second == nullptr)\n\ | ||
766 | reinterpret_cast<Binary" << nodeType << "*>(last)->second = " << __var << ";\ | 766 | reinterpret_cast<Binary" << nodeType << "*>(last)->second = " << __var << ";\ | ||
767 | else\nreinterpret_cast<Ternary" << nodeType << "*>(last)->third = " << __var << ";}\ | 767 | else\nreinterpret_cast<Ternary" << nodeType << "*>(last)->third = " << __var << ";}\ | ||
768 | else\n\ | 768 | else\n\ | ||
769 | (*yynode) = " << __var << ";\ | 769 | (*yynode) = " << __var << ";\ | ||
770 | opStack.push_back(OperatorStackItem(" << __var << ", -2));"; | 770 | opStack.push_back(OperatorStackItem(" << __var << ", -2));"; | ||
771 | PUSH_UNARY | 771 | PUSH_UNARY | ||
772 | out << "expectOperator = true; } else\nreturn false; }"; | 772 | out << "expectOperator = true; } else\nreturn false; }"; | ||
773 | } | 773 | } | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 804 | { | |||
861 | out << "else" << endl << "{ return false; }" << endl | 861 | out << "else" << endl << "{ return false; }" << endl | ||
862 | << endl; | 862 | << endl; | ||
863 | 863 | | |||
864 | 864 | | |||
865 | if (globalSystem.generateAst) | 865 | if (globalSystem.generateAst) | ||
866 | { | 866 | { | ||
867 | if(isOperatorSymbol(sym)) | 867 | if(isOperatorSymbol(sym)) | ||
868 | { | 868 | { | ||
869 | out << "AstNode *olast, *last = 0;" | 869 | out << "AstNode *olast, *last = nullptr;" | ||
870 | "while(!opStack.empty())\n" | 870 | "while(!opStack.empty())\n" | ||
871 | "{" | 871 | "{" | ||
872 | "olast = last;" | 872 | "olast = last;" | ||
873 | "last = opStack.last().n;" | 873 | "last = opStack.last().n;" | ||
874 | "if(olast)\n" | 874 | "if(olast)\n" | ||
875 | "last->endToken = olast->endToken;" | 875 | "last->endToken = olast->endToken;" | ||
876 | "opStack.pop_back();" | 876 | "opStack.pop_back();" | ||
877 | "}" << endl; | 877 | "}" << endl; | ||
▲ Show 20 Lines • Show All 284 Lines • ▼ Show 20 Line(s) | 1153 | out << "// The copyCurrentState() and restoreState() methods are only declared" << endl | |||
1162 | << "// This method is only called for ParserState objects != 0" << endl | 1162 | << "// This method is only called for ParserState objects != 0" << endl | ||
1163 | << "// and should restore the parser state given as argument." << endl | 1163 | << "// and should restore the parser state given as argument." << endl | ||
1164 | << "void restoreState(ParserState *state);" << endl; | 1164 | << "void restoreState(ParserState *state);" << endl; | ||
1165 | } | 1165 | } | ||
1166 | 1166 | | |||
1167 | out << "Parser() {" << endl; | 1167 | out << "Parser() {" << endl; | ||
1168 | if (globalSystem.generateAst) | 1168 | if (globalSystem.generateAst) | ||
1169 | { | 1169 | { | ||
1170 | out << "memoryPool = 0;" << endl; | 1170 | out << "memoryPool = nullptr;" << endl; | ||
1171 | } | 1171 | } | ||
1172 | 1172 | | |||
1173 | out << "tokenStream = 0;" << endl | 1173 | out << "tokenStream = nullptr;" << endl | ||
1174 | << "yytoken = Token_EOF;" << endl | 1174 | << "yytoken = Token_EOF;" << endl | ||
1175 | << "mBlockErrors = false;" << endl; | 1175 | << "mBlockErrors = false;" << endl; | ||
1176 | 1176 | | |||
1177 | if (globalSystem.parserclassMembers.constructorCode.empty() == false) | 1177 | if (globalSystem.parserclassMembers.constructorCode.empty() == false) | ||
1178 | { | 1178 | { | ||
1179 | out << endl << "// user defined constructor code:" << endl; | 1179 | out << endl << "// user defined constructor code:" << endl; | ||
1180 | GenerateMemberCode gen(out, Settings::MemberItem::ConstructorCode); | 1180 | GenerateMemberCode gen(out, Settings::MemberItem::ConstructorCode); | ||
1181 | for(QList<Settings::MemberItem*>::iterator it = | 1181 | for(QList<Settings::MemberItem*>::iterator it = | ||
▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines |