argElement *doArgs(TreeNode *p) { //printf("doArgs\n"); //printf("TreeNode->state:%s\n", p->state); switch (p->productionRule) { case 1: { TreeNode *p1 = p->firstChild; TreeNode *p3 = p1->rightBrother->rightBrother; argElement *arg1 = (argElement *)malloc(sizeof(argElement)); arg1->type = doExp(p1); argElement *arg2 = doArgs(p3); arg1->next = arg2; return arg1; break; } case 2: { TreeNode *p1 = p->firstChild; argElement *arg1 = (argElement *)malloc(sizeof(argElement)); arg1->type = doExp(p1); arg1->next = NULL; //if (arg1 == NULL) printf("wow...\n"); return arg1; break; } } }
void KstJS::doArgs() { static bool executing = false; if (!_jsPart || executing) { QTimer::singleShot(0, this, SLOT(doArgs())); return; } executing = true; QStringList a = QDeepCopy<QStringList>(_args); _args.clear(); for (QStringList::ConstIterator i = a.begin(); i != a.end(); ++i) { _jsPart->execute(*i); } executing = false; }
void KstJS::processArguments(const QString& args) { _args.append(args); QTimer::singleShot(0, this, SLOT(doArgs())); }
/// \fn int main(int argc, char *argv[]) /// \brief Entry point of the application. /// /// \file main.cpp /// \brief Entry point for the GUI application /// /// This file contains main(). /////////////////// /// \brief main /// \param argc /// \param argv /// \return /// int main(int argc, char *argv[]) { #if QT_DEBUG // logger creation #endif // initialize resources at startup (qrc file loading) #if defined(Q_OS_MAC) Q_INIT_RESOURCE(eddypro_mac); #elif defined(Q_OS_WIN) Q_INIT_RESOURCE(eddypro_win); #else Q_INIT_RESOURCE(eddypro_lin); #endif qApp->setAttribute(Qt::AA_UseHighDpiPixmaps); #if defined(Q_OS_MAC) qApp->setAttribute(Qt::AA_DontShowIconsInMenus); // workaround necessary in case of widget painting issues // qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); #endif QApplication::setColorSpec(QApplication::ManyColor); // QApplication::setDesktopSettingsAware(false); QApplication::setEffectEnabled(Qt::UI_AnimateMenu); QApplication::setEffectEnabled(Qt::UI_FadeMenu); QApplication::setEffectEnabled(Qt::UI_AnimateCombo); QApplication::setEffectEnabled(Qt::UI_AnimateTooltip); QApplication::setEffectEnabled(Qt::UI_FadeTooltip); /// /// A set of flags to workaroud issues in specific cases /// // QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL); QCoreApplication::setAttribute(Qt::AA_UseOpenGLES); // QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL); // QCoreApplication::setAttribute(Qt::AA_ForceRasterWidgets); // QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); // QCoreApplication::setAttribute(Qt::AA_SetPalette); // QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); QApplication app(argc, argv); app.setApplicationName(Defs::APP_NAME); app.setApplicationDisplayName(Defs::APP_NAME); app.setOrganizationName(Defs::ORG_NAME); app.setOrganizationDomain(Defs::ORG_DOMAIN); qDebug() << "currentUnicodeVersion" << QChar::currentUnicodeVersion(); // fix order of library paths // see https://bugreports.qt-project.org/browse/QTBUG-40738 QString executable = QLatin1String(argv[0]); QtHelper::prependApplicationPathToLibraryPaths(executable); qDebug() << "library paths" << QApplication::libraryPaths(); #if defined(Q_OS_MAC) // file to open at start auto fileToOpen = QString(); // install event filter to open clicked files in Mac OS X OpenFileFilter openFileFilter; app.installEventFilter(&openFileFilter); app.processEvents(); auto requestedFile = openFileFilter.fileRequested(); if (requestedFile.endsWith(QStringLiteral(".eddypro"))) { fileToOpen = requestedFile; } #endif // custom ttf setup int fontId_1 = QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/fonts/OpenSans-Regular.ttf")); Q_ASSERT(fontId_1 != -1); qDebug() << QFontDatabase::applicationFontFamilies(fontId_1); int fontId_2 = QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/fonts/OpenSans-Italic.ttf")); Q_ASSERT(fontId_2 != -1); qDebug() << QFontDatabase::applicationFontFamilies(fontId_2); int fontId_3 = QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/fonts/OpenSans-Bold.ttf")); Q_ASSERT(fontId_3 != -1); qDebug() << QFontDatabase::applicationFontFamilies(fontId_3); int fontId_4 = QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/fonts/OpenSans-Semibold.ttf")); Q_ASSERT(fontId_4 != -1); qDebug() << QFontDatabase::applicationFontFamilies(fontId_4); int fontId_5 = QFontDatabase::addApplicationFont(QStringLiteral(":/fonts/fonts/OpenSans-BoldItalic.ttf")); Q_ASSERT(fontId_5 != -1); qDebug() << QFontDatabase::applicationFontFamilies(fontId_5); // load translation file embedded in resources QTranslator appTranslator; bool ok = appTranslator.load(QStringLiteral(":/tra/en")); qDebug() << "loading translation:" << ok; app.installTranslator(&appTranslator); // working dir QDir dir = QDir::current(); qDebug() << "current dir" << dir.absolutePath(); QString currentWorkingDir = QDir::currentPath(); QString installationDir = qApp->applicationDirPath(); qDebug() << "currentWorkingDir" << currentWorkingDir; qDebug() << "installationDir" << installationDir; if (currentWorkingDir != installationDir) { QDir::setCurrent(installationDir); } qDebug() << "currentWorkingDir" << QDir::currentPath(); qDebug() << "currentWorkingDir" << QCoreApplication::applicationDirPath(); // styles qDebug() << "------------------------------------------------------------"; qDebug() << "Default Style: " << app.style()->metaObject()->className(); MyStyle myStyle(app.style()->objectName()); app.setStyle(&myStyle); #if defined(Q_OS_WIN) FileUtils::loadStyleSheetFile(QStringLiteral(":/css/winstyle")); #elif defined(Q_OS_MAC) FileUtils::loadStyleSheetFile(QStringLiteral(":/css/macstyle")); #elif defined(Q_OS_LINUX) FileUtils::loadStyleSheetFile(QStringLiteral(":/css/linstyle")); #endif QString appEnvPath = FileUtils::setupEnv(); if (appEnvPath.isEmpty()) { WidgetUtils::critical(nullptr, QObject::tr("Cannot proceed"), QObject::tr("Home Path not available.")); return 1000; } qDebug() << "appEnvPath" << appEnvPath; // check for command line arguments QTextStream stream(stdout); //#ifdef QT_DEBUG // bool getLogFile = true; //#else bool getLogFile = false; //#endif QString filename = doArgs(app.arguments(), stream, &getLogFile); qDebug() << "filename:" << filename; qDebug() << "getLogFile:" << getLogFile; #if defined(Q_OS_MAC) if (!fileToOpen.isEmpty()) { filename = fileToOpen; } #endif // log file QFile logFile(appEnvPath + QLatin1Char('/') + Defs::LOG_FILE_DIR + QLatin1Char('/') + Defs::APP_NAME_LCASE + QStringLiteral("_gui.") + Defs::LOG_FILE_EXT); if (getLogFile) { if (logFile.size() > 1048576) logFile.remove(); if (logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) { outputStream = new QTextStream(&logFile); QtMessageHandler oldMsgHandler(qInstallMessageHandler(logOutput)); Q_UNUSED(oldMsgHandler); } else { qDebug() << "Error opening logFile file '" << Defs::APP_NAME_LCASE << "'. All debug output redirected to console."; } } // create and show splash screen QPixmap pixmap(QStringLiteral(":/icons/splash-img")); #if defined(Q_OS_MAC) pixmap.setDevicePixelRatio(2.0); #endif CustomSplashScreen splash(pixmap, Qt::WindowStaysOnTopHint); auto show_splash = GlobalSettings::getFirstAppPersistentSettings(Defs::CONFGROUP_GENERAL, Defs::CONF_GEN_SHOW_SPLASH, true).toBool(); #if defined(Q_OS_MAC) auto is_full_screen_set = GlobalSettings::getFirstAppPersistentSettings(Defs::CONFGROUP_WINDOW, Defs::CONF_WIN_FULLSCREEN, true).toBool(); if (is_full_screen_set) { show_splash = false; } #endif qDebug() << "show_splash:" << show_splash; if (show_splash) { QFont splashFont; splashFont.setFamily(QStringLiteral("Open Sans")); splashFont.setBold(false); splashFont.setPixelSize(12); splash.setFont(splashFont); splash.setMessageRect(QRect(0, 427, 600, 25), Qt::AlignCenter); // Setting the message position. splash.show(); splash.showStatusMessage(QObject::tr("Initializing...")); } qApp->processEvents(); QLocale::setDefault(QLocale::C); if (show_splash) { splash.showStatusMessage(QObject::tr("Loading...")); splash.setProgressValue(20); splash.setProgressValue(30); splash.repaint(); } qApp->processEvents(); //#if defined(Q_OS_MAC) // MainWindow mainWin(filename, appEnvPath, &splash, 0, // Qt::WindowFlags() // Window|WindowTitleHint|WindowSystemMenuHint|WindowMinMaxButtonsHint|WindowCloseButtonHint|WindowFullscreenButtonHint // Qt::Window | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint // ); //#elif defined(Q_OS_WIN) MainWindow mainWin(filename, appEnvPath, &splash); //#endif if (show_splash) { splash.setProgressValue(40); splash.setProgressValue(50); splash.setProgressValue(60); } mainWin.show(); if (show_splash) { splash.setProgressValue(70); splash.setProgressValue(80); splash.clearMessage(); splash.showStatusMessage(QObject::tr("Loading complete.")); splash.setProgressValue(90); splash.setProgressValue(100); splash.repaint(); } // qApp->processEvents(); qDebug() << "applicationDisplayName" << qApp->applicationDisplayName(); #if defined(Q_OS_MAC) qDebug() << "____________________________________________________"; auto docExtraction = extractDocs(installationDir); qDebug() << "docs.zip extraction:" << docExtraction; qDebug() << "____________________________________________________"; #endif qDebug() << "++++++++++++++++++++++++++++++++++++++++++++++++++++"; const int returnVal = app.exec(); // cleanup // if (logFile) // { // logFile->close(); // delete logFile; // } if (outputStream) { delete outputStream; } return returnVal; }
// // main // int main(int argc, char **argv) { #ifdef __unix__ // Load wxWindows Stub (for pop-up dialogues) (void)dlopen(WXSTUB_DLL_NAME, RTLD_NOW|RTLD_NODELETE); #endif #ifdef LOG char buff[1000]; if (getUserDataDir(buff, sizeof(buff)) != 0) { strcpy(buff, "c:"); } strcat(buff, "/gdbServer.log"); FILE *errorLog = fopen(buff, "wt"); Logging::setLogFileHandle(errorLog); #endif Logging::setLoggingLevel(100); LOGGING; #ifdef LOG Logging::print("Args = "); for (int index=0; index<argc; index++) { Logging::printq("%s ", argv[index]); } Logging::printq("\n"); #endif if (signal(SIGINT, signalHandler) == SIG_IGN) { (void)signal(SIGINT, SIG_IGN); } shared = SharedPtr(new Shared(TARGET_TYPE)); USBDM_ErrorCode rc = doArgs(argc, argv); if (rc != BDM_RC_OK) { Logging::print("Error %s\n", USBDM_GetErrorString(rc)); exit (-1); } Logging::print("After doArgs\n"); rc = shared->initBdm(); if (rc != BDM_RC_OK) { Logging::print("Error %s\n", USBDM_GetErrorString(rc)); exit (-1); } Logging::print("After shared->initBdm()\n"); // setDefaultWindowParent(FindEclipseWindowHwnd()); GdbInOutPipe *gdbInOut = GdbInOutPipe::getGdbInOut(); Logging::print("After GdbInOutPipe::getGdbInOut()\n"); // Redirect stdout to stderr dup2(2,1); if (gdbInOut == NULL) { Logging::print("Error gdbInOut() creation failed\n"); exit (-1); } Logging::print("After gdbInOut()\n"); // Now do the actual processing of GDB messages gdbHandlerInit(gdbInOut, *shared->getCurrentDevice(), callBack); gdbLoop(gdbInOut); gdbInOut->finish(); delete gdbInOut; return 0; }
// // main // int main(int argc, char **argv) { (void) signal(SIGINT, SIG_IGN); if (progressTimer != NULL) { delete progressTimer; } progressTimer = new ProgressTimer(NULL, 1000); progressTimer->restart("Initialising..."); #ifdef LOG FILE *errorLog = fopen("c:\\delme.log","wt"); setLogFileHandle(errorLog); #if TARGET == ARM // ARM_SetLogFile(errorLog); #endif #endif print("gdbServer(): Starting\n"); print("Starting, Time = %f\n", progressTimer->elapsedTime()); USBDM_ErrorCode rc = doArgs(argc, argv); if (rc != BDM_RC_OK) { usage(); reportError(rc); exit(1); } print("After doArgs, Time = %f\n", progressTimer->elapsedTime()); rc = usbdmInit(TARGET_TYPE); print("After usbdmInit, Time = %f\n", progressTimer->elapsedTime()); GdbInput *gdbInput = new GdbInput(stdin); print("After gdbInput, Time = %f\n", progressTimer->elapsedTime()); GdbOutput *gdbOutput = new GdbOutput(stdout); print("After gdbOutput, Time = %f\n", progressTimer->elapsedTime()); // Redirect stdout to stderr dup2(2,1); // int outHandle = dup(fileno(stderr)); // freopen("delme.txt", "wb", stdout); if (!gdbInput->createThread() || (gdbInput == NULL) || (gdbOutput == NULL)) { // Quit immediately as we have no way to convey error to gdb reportError(BDM_RC_FAIL); exit (-1); } print("After createThread, Time = %f\n", progressTimer->elapsedTime()); if (rc != BDM_RC_OK) { reportError(rc); const GdbPacket *pkt; print("gdbServer(): usbdmInit() Failed, waiting for GDB to collect error\n"); fprintf(stderr, "gdbServer(): USBDM Initialisation failed, waiting for GDB to collect error\n"); usbdmClose(); for (int i = 0; i<3; i++) { if (gdbInput->isEOF()) { break; } pkt = gdbInput->getGdbPacket(); if (pkt != NULL) { gdbOutput->sendAck(); gdbOutput->setErrorMessage("E.fatal.No connection"); gdbOutput->sendErrorMessage(); } }; fclose(stdin); return -1; } // Now do the actual processing of GDB messages handleGdb(gdbInput, gdbOutput, deviceData, progressTimer); usbdmClose(); print("gdbServer() - Exiting\n"); fprintf(stderr, "gdbServer() - Exiting\n"); #ifdef LOG fflush(errorLog); fclose(errorLog); #endif fflush(stdout); fflush(stderr); fclose(stdin); fclose(stdout); return 0; }
Type doExp(TreeNode *p) { // printf("doExp\n"); // printf("TreeNode->state:%s\n", p->state); // printf("TreeNode->productionRule: %d\n", p->productionRule); if(strcmp(p->state, "Exp") == 0) { TreeNode *tempNode = p->firstChild;//产生式右边第一个符号 switch (p->productionRule) { case 1:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother; //Type type = (Type)malloc(sizeof(struct Type_)); Type t1 = doExp(tempNode); Type t2 = doExp(temp2Node); if (tempNode->productionRule > 16 || tempNode->productionRule < 14) { //不符合唯一的三个能当右值的产生式 printf("Error type 6 at line %d: left expression illegal for assign\n", p->line); } if(t1 != NULL && t2 != NULL) { if(type_equal(t1, t2)) { // printf("Exp ASSIGNOP Exp\n"); // printf("tempNode->firstChild->addr_sp: %d\n", tempNode->firstChild->addr_sp); fprintf(out_fp, "\tlw $t0, %d($sp)\n", temp2Node->firstChild->addr_sp - ADDR); fprintf(out_fp, "\tsw $t0, %d($sp)\n", tempNode->firstChild->addr_sp - ADDR); return t1;//类型匹配 } else if(!type_equal(t1, t2)) { printf("Error type 7 at line %d '=' type mismatch\n", p->line);//类型不匹配 OUT = false;//表示语义分析错误,删除已生成的目标文件 } } break; //exp = exp } case 2:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother; Type type = (Type)malloc(sizeof(struct Type_)); Type t1 = doExp(tempNode); Type t2 = doExp(temp2Node); if(t1 != NULL && t2 != NULL) { if(type_equal(t1, t2)) { type = t1; ADDR -= 4; p->firstChild->addr_sp = ADDR;//将表达式结果存在该地址处 fprintf(out_fp, "\taddi $sp, $sp, -4\n"); fprintf(out_fp, "\tlw $t0, %d($sp)\n", tempNode->firstChild->addr_sp); fprintf(out_fp, "\tlw $t1, %d($sp)\n", temp2Node->firstChild->addr_sp); fprintf(out_fp, "\tand $t0, $t0, $t1\n"); fprintf(out_fp, "\tsw $t0, 0($sp)\n"); return type;//类型匹配 } else if(!type_equal(t1, t2)) { printf("Error type 7 at line %d '&&' type mismatch\n", p->line);//类型不匹配 OUT = false; } } break; //Exp AND Exp } case 3:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother; Type type = (Type)malloc(sizeof(struct Type_)); Type t1 = doExp(tempNode); Type t2 = doExp(temp2Node); if(t1 != NULL && t2 != NULL) { if(type_equal(t1, t2)) { type = t1; ADDR -= 4; p->firstChild->addr_sp = ADDR;//将表达式结果存在该地址处 fprintf(out_fp, "\taddi $sp, $sp, -4\n"); fprintf(out_fp, "\tlw $t0, %d($sp)\n", tempNode->firstChild->addr_sp); fprintf(out_fp, "\tlw $t1, %d($sp)\n", temp2Node->firstChild->addr_sp); fprintf(out_fp, "\tor $t0, $t0, $t1\n"); fprintf(out_fp, "\tsw $t0, 0($sp)\n"); return type;//类型匹配 } else if(!type_equal(t1, t2)) { printf("Error type 7 at line %d '||' type mismatch\n", p->line);//类型不匹配 OUT = false; } } break; //Exp OR Exp } case 4:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother; Type type = (Type)malloc(sizeof(struct Type_)); Type t1 = doExp(tempNode); Type t2 = doExp(temp2Node); if(t1 != NULL && t2 != NULL) { if(type_equal(t1, t2)) { type = t1; return type;//类型匹配 } else if(!type_equal(t1, t2)) { printf("Error type 7 at line %d 'RELOP' type mismatch\n", p->line);//类型不匹配 } } break; //Exp RELOP Exp } case 5:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother; Type type = (Type)malloc(sizeof(struct Type_)); Type t1 = doExp(tempNode); Type t2 = doExp(temp2Node); if(t1 != NULL && t2 != NULL) { if(type_equal(t1, t2)) { type = t1; // printf("t1->u.basic: %d\n", t1->u.basic); ADDR -= 4; p->firstChild->addr_sp = ADDR; fprintf(out_fp, "\taddi $sp, $sp, -4\n"); fprintf(out_fp, "\tlw $t0, %d($sp)\n", tempNode->firstChild->addr_sp - ADDR); fprintf(out_fp, "\tlw $t1, %d($sp)\n", temp2Node->firstChild->addr_sp - ADDR); fprintf(out_fp, "\tadd $t0, $t0, $t1\n"); fprintf(out_fp, "\tsw $t0, 0($sp)\n"); return type;//类型匹配 } else if(!type_equal(t1, t2)) { printf("Error type 7 at line %d '+' type mismatch\n", p->line);//类型不匹配 OUT = false; } } break; //Exp PLUS Exp } case 6:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother; Type type = (Type)malloc(sizeof(struct Type_)); Type t1 = doExp(tempNode); Type t2 = doExp(temp2Node); if(t1 != NULL && t2 != NULL) { if(type_equal(t1, t2)) { type = t1; ADDR -= 4; p->firstChild->addr_sp = ADDR; fprintf(out_fp, "\taddi $sp, $sp, -4\n"); fprintf(out_fp, "\tlw $t0, %d($sp)\n", tempNode->firstChild->addr_sp - ADDR); fprintf(out_fp, "\tlw $t1, %d($sp)\n", temp2Node->firstChild->addr_sp - ADDR); fprintf(out_fp, "\tsub $t0, $t0, $t1\n"); fprintf(out_fp, "\tsw $t0, 0($sp)\n"); return type;//类型匹配 } else if(!type_equal(t1, t2)) { printf("Error type 7 at line %d '-' type mismatch\n", p->line);//类型不匹配 } } break; //Exp MINUS Exp } case 7:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother; Type type = (Type)malloc(sizeof(struct Type_)); Type t1 = doExp(tempNode); Type t2 = doExp(temp2Node); if(t1 != NULL && t2 != NULL) { if(type_equal(t1, t2)) { type = t1; ADDR -= 4; p->firstChild->addr_sp = ADDR; fprintf(out_fp, "\taddi $sp, $sp, -4\n"); fprintf(out_fp, "\tlw $t0, %d($sp)\n", tempNode->firstChild->addr_sp - ADDR); fprintf(out_fp, "\tlw $t1, %d($sp)\n", temp2Node->firstChild->addr_sp - ADDR); fprintf(out_fp, "\tmul $t0, $t0, $t1\n"); fprintf(out_fp, "\tsw $t0, 0($sp)\n"); return type;//类型匹配 } else if(!type_equal(t1, t2)) { printf("Error type 7 at line %d '*' type mismatch\n", p->line);//类型不匹配 } } break; //Exp STAR Exp } case 8:{TreeNode *temp2Node = tempNode->rightBrother->rightBrother; Type type = (Type)malloc(sizeof(struct Type_)); Type t1 = doExp(tempNode); Type t2 = doExp(temp2Node); if(t1 != NULL && t2 != NULL) { if(type_equal(t1, t2)) { type = t1; ADDR -= 4; p->firstChild->addr_sp = ADDR; fprintf(out_fp, "\taddi $sp, $sp, -4\n"); fprintf(out_fp, "\tlw $t0, %d($sp)\n", tempNode->firstChild->addr_sp - ADDR); fprintf(out_fp, "\tlw $t1, %d($sp)\n", temp2Node->firstChild->addr_sp - ADDR); fprintf(out_fp, "\tdiv $t0, $t0, $t1\n"); fprintf(out_fp, "\tsw $t0, 0($sp)\n"); return type;//类型匹配 } else if(!type_equal(t1, t2)) { printf("Error type 7 at line %d '/' type mismatch\n", p->line);//类型不匹配 } } break; //Exp DIV Exp } case 9:return doExp(tempNode->rightBrother); //LP Exp RP case 10:return doExp(tempNode->rightBrother); //MINUS Exp case 11:return doExp(tempNode->rightBrother); //NOT Exp case 12:{funcTableElement *func = searchFunc(tempNode->value.idValue); if(func == NULL) { varElement *var = searchAll(tempNode->value.idValue); if (var != NULL) { printf("Error type 11 at line %d: normal variable %s uses '()'\n", p->line, tempNode->value.idValue); } else printf("Error type 4 at line %d: undefined function %s\n", p->line, tempNode->value.idValue); return NULL; } TreeNode *argNode = tempNode->rightBrother->rightBrother; argElement *args = doArgs(argNode); if (compareArgs(func->argListHeader, args) == 0) { //参数匹配有问题 printf("Error type 9 at line %d: function var list not matched %s\n", p->line, tempNode->value.idValue); return func->type; } break; //ID LP Args RP } case 13:{funcTableElement *func = searchFunc(tempNode->value.idValue); if(func == NULL) { varElement *var = searchAll(tempNode->value.idValue); if (var != NULL) { printf("Error type 11 at line %d: normal variable %s uses '()'\n", p->line, tempNode->value.idValue); OUT = false; } else { printf("Error type 4 at line %d:undefined function %s\n", p->line, tempNode->value.idValue); OUT = false; } return NULL; } else if (func->argListHeader != NULL) { //函数定义中有参数而调用没有 printf("Error type 9 at line %d:function var list not matched %s\n", p->line, tempNode->value.idValue); OUT = false; return func->type; } break; //ID LP RP } case 14:{Type type = (Type)malloc(sizeof(struct Type_)); TreeNode *temp2Node = tempNode->rightBrother->rightBrother; Type t1 = doExp(tempNode); Type t2 = doExp(temp2Node); if(tempNode != NULL && temp2Node != NULL) { if(t1->kind != ARRAY) { printf("Error type 10 at line %d: normal variable uses '[]'\n", p->line); OUT = false; } else if(t2->u.basic != 0) { printf("Error type 12 at line %d:int required\n", p->line); OUT = false; } else { type = doExp(tempNode)->u.array.elem; // printf("tempNode->firstChild->addr_sp: %d\n", tempNode->firstChild->addr_sp); tempNode->addr_sp = tempNode->firstChild->addr_sp - temp2Node->firstChild->value.intValue * 4; return type; } } break; //Exp LB Exp RB } case 15:{ TreeNode *p3 = tempNode->rightBrother->rightBrother; Type t = doExp(tempNode); if(t != NULL) { if(t->kind != STRUCTURE) { printf("Error type 13 at line %d: error use of operator '.'\n", p->line); } else { //showStructMember(t); ; varElement *field = t->u.var; while(field != NULL) { if(strcmp(field->name, p3->value.idValue) == 0) { return field->type; } field = field->next; } printf("Error type 14 at line %d:struct member %s undefined\n", p->line, tempNode->rightBrother->rightBrother->value.idValue); //结构体成员未定义 } } break; //Exp DOT ID } case 16:{Type type = (Type)malloc(sizeof(struct Type_)); varElement *id = searchAll(tempNode->value.idValue); //在符号表中寻找是否定义 if(id == NULL) { printf("Error type 1 at line %d:undefined variable %s\n", p->line, tempNode->value.idValue); OUT = false; } else { type = id->type; tempNode->addr_sp = id->addr_sp; printf("tempNode->addr_sp: %d\n", id->addr_sp); return type; } break; //ID } case 17:{Type type = (Type)malloc(sizeof(struct Type_)); type->kind = BASIC; type->u.basic = 0; ADDR -= 4; tempNode->addr_sp = ADDR; fprintf(out_fp, "\taddi $sp, $sp, -4\n"); fprintf(out_fp, "\tli $t0, %d\n", tempNode->value.intValue); fprintf(out_fp, "\tsw $t0, 0($sp)\n"); return type; //INT } case 18:{Type type = (Type)malloc(sizeof(struct Type_)); type->kind = BASIC; type->u.basic = 1; ADDR -= 4; tempNode->addr_sp = ADDR; fprintf(out_fp, "\taddi $sp, $sp, -4\n"); fprintf(out_fp, "\tli $t0, %f\n", tempNode->value.floatValue); fprintf(out_fp, "\tsw $t0, 0($sp)\n"); return type; //FLOAT } } } return NULL; }