void CSVWorld::GenericCreator::setScope (unsigned int scope) { mScopes = scope; int count = (mScopes & CSMWorld::Scope_Content) + (mScopes & CSMWorld::Scope_Project) + (mScopes & CSMWorld::Scope_Session); // scope selector widget if (count>1) { mScope = new QComboBox (this); insertAtBeginning (mScope, false); if (mScopes & CSMWorld::Scope_Content) addScope ("Content", CSMWorld::Scope_Content, "Record will be stored in the currently edited content file."); if (mScopes & CSMWorld::Scope_Project) addScope ("Project", CSMWorld::Scope_Project, "Record will be stored in a local project file.<p>" "Record will be created in the reserved namespace \"project\".<p>" "Record is available when running OpenMW via OpenCS."); if (mScopes & CSMWorld::Scope_Session) addScope ("Session", CSMWorld::Scope_Session, "Record exists only for the duration of the current editing session.<p>" "Record will be created in the reserved namespace \"session\".<p>" "Record is not available when running OpenMW via OpenCS."); connect (mScope, SIGNAL (currentIndexChanged (int)), this, SLOT (scopeChanged (int))); mScopeLabel = new QLabel ("Scope", this); insertAtBeginning (mScopeLabel, false); mScope->setCurrentIndex (0); }
llvm::Value * CodeGen::generateCodeValue(ValueAST *ast) { addScope(ast->name); llvm::Value * exprCode = generateCodeExpr(ast->expr.get()); removeScope(); addScopedValue(ast->name, exprCode); return exprCode; }
/* * Construtor: * - cria o estado Lua * - cria superficie grafica * - inicializa estruturas internas de apoio * - inicializa bibliotecas disponiveis ao NCLua * - associa Player ao seu estado Lua */ LuaPlayer::LuaPlayer (string mrl) : Player(mrl), Thread() { chdir(getPath(mrl).c_str()); // execucao a partir do diretorio fonte this->L = luaL_newstate(); // estado Lua #if HAVE_COMPSUPPORT this->im = ((InputManagerCreator*)(cm->getObject("InputManager")))(); this->surface = ((SurfaceCreator*)(cm->getObject("Surface")))(NULL, 0, 0); #else this->im = InputManager::getInstance(); this->surface = new DFBSurface(); #endif this->surface->setCaps(this->surface->getCap("ALPHACHANNEL")); this->im->addApplicationInputEventListener(this); // ESCOPO this->currentScope = ""; // escopo global this->scopes = new map<string, struct scopeInfo*>; addScope("", TYPE_PRESENTATION, -1, -1); // a partir de um estado Lua eh possivel chegar ao seu Player lua_pushlightuserdata(this->L, this); // [ LuaPlayer* ] lua_setfield(this->L, LUA_REGISTRYINDEX, LUAPLAYER_PLAYER); // [ ] // INNICIALIZACAO DE BIBLIOTECAS DISPONIVEIS AO NCLUA // biblioteca padrao luaL_openlibs(this->L); // modulo 'event' lua_pushcfunction(this->L, luaopen_event); // [ l_event ] lua_call(this->L, 0, 0); // [ ] this->tcp_running = false; // modulo 'canvas' this->lock(); lua_pushcfunction(this->L, luaopen_canvas); // [ l_canvas ] lua_call(this->L, 0, 0); // [ ] this->unlock(); // estado inicial this->running = true; this->played = false; this->loaded = false; this->isHandler = false; }
llvm::Function * CodeGen::generateCodeDef(DefAST *ast) { // add def name to scope addScope(ast->name); // argument types vector<llvm::Type*> args(ast->args.size(), llvm::Type::getDoubleTy(context)); // return type auto retType = llvm::Type::getDoubleTy(context); // complete function type llvm::FunctionType *funcType = llvm::FunctionType::get(retType, args, false); llvm::Function * func = llvm::Function::Create(funcType, llvm::Function::ExternalLinkage, ast->name, module.get()); unsigned i = 0; for (auto funcarg = func->arg_begin(); i != ast->args.size(); ++funcarg, ++i) { funcarg->setName(ast->args[i]); addScopedValue(ast->args[i], funcarg); } llvm::BasicBlock *block = llvm::BasicBlock::Create(context, "entry", func); Builder.SetInsertPoint(block); if (llvm::Value * result = generateCodeExpr(ast->body.get())) { Builder.CreateRet(result); string verifyS; llvm::raw_string_ostream verifyE(verifyS); if (verifyFunction(*func, &verifyE)) { func->eraseFromParent(); error = "something wrong with function \"" + ast->name + "\": " + verifyS; return nullptr; } // remove the def name scope removeScope(); return func; } else { func->eraseFromParent(); error = "error creating function body: " + error; return nullptr; } }
/** Creates a hash code of the specified string and adds this to the internal hash register. arg: String with maximum 20 characters **/ void LithneClass::addScope( String _group ) { addScope( hash(_group) ); }
void ofxGuiPanel::buildFromXml() { int numberOfTags = mGlobals->mXml.getNumTags("OBJECT"); if(numberOfTags > 0) { for(int i = 0; i < numberOfTags; i++) { mGlobals->mXml.pushTag("OBJECT", i); int id = mGlobals->mXml.getValue("ID", 0); string type = mGlobals->mXml.getValue("TYPE", ""); string name = mGlobals->mXml.getValue("NAME", ""); int width = mGlobals->mXml.getValue("WIDTH", 0); int height = mGlobals->mXml.getValue("HEIGHT", 0); int display = mGlobals->mXml.getValue("DISPLAY", 0); int steps = mGlobals->mXml.getValue("STEPS", 0); int mode = mGlobals->mXml.getValue("MODE", 0); string image = mGlobals->mXml.getValue("IMAGE", ""); if(type == "SLIDER") { float min = mGlobals->mXml.getValue("MIN", 0.0f); float max = mGlobals->mXml.getValue("MAX", 0.0f); float value = mGlobals->mXml.getValue("VALUE", 0.0f); ofxGuiSlider* slider = addSlider(id, name, width, height, min, max, value, display, steps); slider->buildFromXml(); } else if(type == "XYPAD") { float minx = mGlobals->mXml.getValue("MIN_X", 0.0f); float miny = mGlobals->mXml.getValue("MIN_Y", 0.0f); float maxx = mGlobals->mXml.getValue("MAX_X", 0.0f); float maxy = mGlobals->mXml.getValue("MAX_Y", 0.0f); float valuex = mGlobals->mXml.getValue("VALUE_X", 0.0f); float valuey = mGlobals->mXml.getValue("VALUE_Y", 0.0f); ofxPoint2f min = ofxPoint2f(minx, miny); ofxPoint2f max = ofxPoint2f(maxx, maxy); ofxPoint2f value = ofxPoint2f(valuex, valuey); ofxGuiXYPad* xypad = addXYPad(id, name, width, height, min, max, value, display, steps); xypad->buildFromXml(); } else if(type == "POINTS") { float minx = mGlobals->mXml.getValue("MIN_X", 0.0f); float miny = mGlobals->mXml.getValue("MIN_Y", 0.0f); float maxx = mGlobals->mXml.getValue("MAX_X", 0.0f); float maxy = mGlobals->mXml.getValue("MAX_Y", 0.0f); float valuex = mGlobals->mXml.getValue("VALUE_X", 0.0f); float valuey = mGlobals->mXml.getValue("VALUE_Y", 0.0f); ofxPoint2f min = ofxPoint2f(minx, miny); ofxPoint2f max = ofxPoint2f(maxx, maxy); ofxPoint2f value = ofxPoint2f(valuex, valuey); ofxGuiPoints* points = addPoints(id, name, width, height, min, max, value, display, steps); points->buildFromXml(); } else if(type == "BUTTON") { bool value = mGlobals->mXml.getValue("VALUE", 0); ofxGuiButton* button = addButton(id, name, width, height, value, mode, image); button->buildFromXml(); } else if(type == "FILES") { string subPath = mGlobals->mXml.getValue("SUBPATH", ""); string suffix = mGlobals->mXml.getValue("SUFFIX", ""); ofxGuiFiles* files = addFiles(id, name, width, height, mGlobals->mXmlfile, subPath, suffix); files->buildFromXml(); } else if(type == "COLOR") { ofRGBA value = ofRGBA(mGlobals->mXml.getValue("VALUE", "FFFFFFFF")); ofxGuiColor* color = addColor(id, name, width, height, value, mode); color->buildFromXml(); } else if(type == "MATRIX") { int xGrid = mGlobals->mXml.getValue("XGRID", 0); int yGrid = mGlobals->mXml.getValue("YGRID", 0); int value = mGlobals->mXml.getValue("VALUE", 0); int spacing = mGlobals->mXml.getValue("SPACING", 0); ofxGuiMatrix* matrix = addMatrix(id, name, width, height, xGrid, yGrid, value, mode, spacing); matrix->buildFromXml(); } else if(type == "SCOPE") { int length = mGlobals->mXml.getValue("LENGTH", 0); float valuex = mGlobals->mXml.getValue("VALUE_X", 0.0f); float valuey = mGlobals->mXml.getValue("VALUE_Y", 0.0f); ofxPoint2f value = ofxPoint2f(valuex, valuey); ofxGuiScope* scope = addScope(id, name, width, height, length, value, mode); scope->buildFromXml(); } else if(type == "KNOB") { float min = mGlobals->mXml.getValue("MIN", 0.0f); float max = mGlobals->mXml.getValue("MAX", 0.0f); float value = mGlobals->mXml.getValue("VALUE", 0.0f); ofxGuiKnob* knob = addKnob(id, name, width, height, min, max, value, display, steps); knob->buildFromXml(); } mGlobals->mXml.popTag(); } } }
void LuaPlayer::setScope(string scopeId, short type, double begin, double end) { addScope(scopeId, type, begin, end); }
bool CodeGen::wrapTopLevelBlockInMain(BlockAST *ast) { // add main to scope addScope("main"); vector<unique_ptr<ASTNode> > * body = ast->body.get(); // generate void main() llvm::FunctionType *voidType = llvm::FunctionType::get(Builder.getVoidTy(), false); llvm::Function *mainFunc = llvm::Function::Create(voidType, llvm::Function::ExternalLinkage, "main", module.get()); // basic block for the top level block llvm::BasicBlock *MainBlock = llvm::BasicBlock::Create(context, "entry", mainFunc); Builder.SetInsertPoint(MainBlock); llvm::Value * lastExpr; for (auto it = body->begin() ; it != body->end(); ++it) { ASTNode * node = it->get(); if (auto x = dynamic_cast<ValueAST*>(node)) { auto code = generateCodeValue(x); if (!code) return false; } else if (auto x = dynamic_cast<DefAST*>(node)) { generateCodeDef(x); Builder.SetInsertPoint(MainBlock); } else if (auto x = dynamic_cast<NumberExprAST*>(node)) { auto code = generateCodeNumber(x); if (!code) return false; lastExpr = code; } else if (auto x = dynamic_cast<BinaryExprAST*>(node)) { auto code = generateCodeBinOp(x); if (!code) return false; lastExpr = code; } else if (auto x = dynamic_cast<CallAST*>(node)) { auto code = generateCodeCall(x); if (!code) return false; lastExpr = code; } else { error = "can't handle ast"; return false; } } llvm::Value *fmt = Builder.CreateGlobalStringPtr("%lg\n"); vector<llvm::Type *> putsArgs; putsArgs.push_back(Builder.getInt8Ty()->getPointerTo()); llvm::ArrayRef<llvm::Type*> argsRef(putsArgs); llvm::FunctionType *putsType = llvm::FunctionType::get(Builder.getInt32Ty(), argsRef, true); llvm::Constant *putsFunc = module->getOrInsertFunction("printf", putsType); vector<llvm::Value *> CallArgs; CallArgs.push_back(fmt); CallArgs.push_back(lastExpr); Builder.CreateCall(putsFunc, CallArgs); Builder.CreateRetVoid(); string verifyS; llvm::raw_string_ostream verifyE(verifyS); if (verifyFunction(*mainFunc, &verifyE)) { mainFunc->eraseFromParent(); error = "something wrong with auto-generated main function: " + verifyS; return false; } // remove the main scope removeScope(); return true; }
int main(){ freopen("lexer_output.txt", "r", stdin); trieRoot = createNewTrieNode(); if(trieRoot == NULL){ perror("Could not create root node!!\n"); return 0; } envTop = NULL; currentScope = totalVariables = 0; addScope(); token t; while(scanf("%d%d", &t.iden, &t.line) != EOF){ fgets(t.value, 1000, stdin); int len = strlen(t.value); t.value[len-1] = '\0'; if(t.value[0] == '-') t.value[0] = '\0'; t.line++; lexemeStream[stream_size++] = t; } // int zz; // for(zz=0;zz<stream_size;zz++) // printf("%d ", lexemeStream[zz].iden); printf("\n"); int i, n = stream_size, lastLineOfDeclaration = -1, lastDataTypeOfDeclaration = -1; int lastDataTypeOfAssignment = -1, lastLineOfAssignment = -1; funcName[0] = '!'; funcName[1] = '\0'; int insideMain = 0, diff = 0; funcParameterCount = 0; for(i=0;i<n;i++){ if(lexemeStream[i].iden == MAIN) insideMain = 1; if(i == 2){ if(lexemeStream[i].iden != MAIN){ assert(lexemeStream[i].iden == FUNC); strcpy(funcName, lexemeStream[i+1].value); } i++; continue; } //check for recursive function calls if(lexemeStream[i].iden == FUNC && !insideMain){ printf("Semantic error: Recursive function calls not allowed.\n"); continue; } if(lexemeStream[i].iden == LSQ){ diff++; continue; } if(lexemeStream[i].iden == RSQ){ diff--; continue; } //store function parameter list if(isDataType(lexemeStream[i].iden) && diff > 0 && !insideMain){ funcParameterType[funcParameterCount++] = lexemeStream[i].iden; } //for function calls inside main, check whether correct function name is used //then check for correct number and types of parameters if(insideMain && i > 0 && lexemeStream[i].iden == IDEN && lexemeStream[i-1].iden == FUNC){ if(strcmp(funcName, lexemeStream[i].value) > 0) printf("Function named %s in line %d not declared.\n", lexemeStream[i].value, lexemeStream[i].line); int j, argumentCount = 0, wrongType = 0; for(j=i+1;j < stream_size && lexemeStream[j].iden != RSQ;j++){ if(lexemeStream[j].iden != IDEN) continue; if(argumentCount < funcParameterCount && getDataType(lexemeStream[j]) != funcParameterType[argumentCount]) wrongType = lexemeStream[j].line; argumentCount++; } if(argumentCount != funcParameterCount) printf("Incorrect number of function arguments in line %d.\n", lexemeStream[j].line); if(wrongType > 0) printf("Type mismatch in function parameters in line %d.\n", wrongType); i = j; continue; } if(lexemeStream[i].iden == LAD){ addScope(); continue; } if(lexemeStream[i].iden == RAD){ deleteScope(); continue; } if(isDataType(lexemeStream[i].iden)){ lastLineOfDeclaration = lexemeStream[i].line; lastDataTypeOfDeclaration = lexemeStream[i].iden; // printf("setting lastlineOfDeclaration = %d because of %d.\n", lastLineOfDeclaration, lexemeStream[i].iden); continue; } if(lexemeStream[i].iden == ASSIGN){ //line number of assignment operator lastLineOfAssignment = lexemeStream[i].line; continue; } if(lexemeStream[i].iden == IDEN){ insert(lexemeStream[i].value); //check if variable is being declared or referenced if(lastLineOfDeclaration == lexemeStream[i].line){ //declared declareVariable(lexemeStream[i], lastDataTypeOfDeclaration); continue; } //referenced referenceVariable(lexemeStream[i]); if(lexemeStream[i].line != lastLineOfAssignment){ lastDataTypeOfAssignment = getDataType(lexemeStream[i]); continue; } if(lexemeStream[i].line == lastLineOfAssignment){ int dataType = getDataType(lexemeStream[i]); if(dataType != lastDataTypeOfAssignment){ printf("Semantic error in line %d: Type mismatch between LHS and RHS in line %d.\n", lexemeStream[i].line, lastLineOfAssignment); } continue; } } } // int c = 0, cc = 0; // EnvStackNode temp = envTop; // while(temp != NULL){ // c++; // EnvListNode ev = temp->ev; // while(ev != NULL){ // cc++; // ev = ev->next; // } // temp = temp->next; // } // printf("Total active scopes : %d and active variables = %d.\n", c, cc); // printf("\ncheck variable stack of size = %d :\n", z); // for(int i=0;i<z;i++){ // int idx = vvv[i]; // if(variableStack[idx] == NULL){ // printf("empty stack at idx = %d\n", idx); // continue; // } // printf("idx = %d has the value = %s\n", idx, variableStack[idx]->node.name); // } return 0; }
void Scopes::updateScopes() { clear(); addScope(new Scope("MockScope1", "People", true, this)); addScope(new Scope("MockScope2", "Music", false, this)); addScope(new Scope("clickscope", "Apps", true, this)); addScope(new Scope("MockScope5", "Videos this is long ab cd ef gh ij kl", true, this)); addScope(new Scope("SingleCategoryScope", "Single", true, this, 1)); addScope(new Scope("MockScope4", "MS4", true, this)); addScope(new Scope("MockScope6", "MS6", true, this)); addScope(new Scope("MockScope7", "MS7", false, this)); addScope(new Scope("MockScope8", "MS8", false, this)); addScope(new Scope("MockScope9", "MS9", false, this)); addScope(new Scope("NullPreviewScope", "NPS", false, this, 1, true)); m_scopesOverview = new ScopesOverview(this); if (!m_loaded) { m_loaded = true; Q_EMIT loadedChanged(); Q_EMIT overviewScopeChanged(); } }
int main(int argc, char *argv[]) { char ch, *str, *strStart; int i; double number; struct String input = {NULL, 0, 0, 5}; /* Kick off scope */ struct Scope *currentScope = NULL; addScope(currentScope, ¤tScope); /* Read input from... */ if (argc == 1) { /* stdin */ while ((ch = getchar()) != '\n' && ch != EOF) { stringAddChar(&input, ch); } } else { /* args */ for (i = 1; i < argc; i++) { stringAddStr(&input, argv[i]); stringAddChar(&input, ' '); } } /* Tokenise */ str = input.str; while (*str != '\0') { strStart = str; if (isspace(*str)) { /* Space */ str++; } else if (*str == '(') { addScope(currentScope, ¤tScope); str++; } else if (*str == ')') { insertToken(currentScope, NUM, '\0', evaluateScope(currentScope, ¤tScope)); str++; } else if ((number = strtold(str, &str)) == 0.0L && (number = strtoconst(str, &str)) == 0.0L) { /* NaN */ insertToken(currentScope, OP, normalise(*str), 0); str++; } else { /* Number */ if ((*strStart == '+' || *strStart == '-') && currentScope->last != NULL && strcmp(currentScope->last->type, OP)) { //Assume this was supposed to be an operation insertToken(currentScope, OP, *strStart, 0); } insertToken(currentScope, NUM, '\0', number); } } /* * TODO: Increase precision * TODO: Allow precision to be specified */ printf("%.15g\n", evaluateScope(currentScope, ¤tScope)); free(input.str); return 0; }