int isBoolean(expr *e) { switch(e->tag){ case E_BOOL_CONST: return 1; case E_INT_CONST: return 0; case E_VARIABLE: if(e->variable->symbol->type == TY_BOOLEAN){ return 1; }else{ return 0; } case E_UNARY: if(isBoolean(e->unary->rand)){ return 1; }else{ return 0; } case E_BINARY: if(isBoolean(e->binary->lrand) && isBoolean(e->binary->rrand)){ return 1; }else{ return 0; } } }
void parseOptions(mc::McrouterOptions& opts, const Array& options) { #ifdef HPHP_OSS // Change defaults for these since they make assumptions about the system opts.asynclog_disable = true; opts.async_spool = ""; opts.stats_logging_interval = 0; opts.stats_root = ""; #endif std::unordered_map<std::string, std::string> dict; for (ArrayIter iter(options); iter; ++iter) { auto key = iter.first().toString().toCppString(); auto val = iter.second(); if (val.isBoolean()) { // false -> toString() == "" which will fail foll::to<bool> dict[key] = val.toBoolean() ? "1" : "0"; } else { dict[key] = val.toString().toCppString(); } } auto errors = opts.updateFromDict(dict); if (!errors.empty()) { mcr_throwOptionException(errors); } }
void Parameter::setValue(float val, int chan) { std::cout << "Setting value of " << chan << " to " << val << std::endl; if (isBoolean()) { if (val > 0.0f) values.set(chan, true); else values.set(chan, false); } else if (isContinuous()) { if (val < (float) possibleValues[0]) { values.set(chan, possibleValues[0]); } else if (val > (float) possibleValues[1]) { values.set(chan, possibleValues[1]); } else { values.set(chan, val); } } else { //int index = (int) val; //if (index >= 0 && index < possibleValues.size()) //{ values.set(chan, val); //} } }
bool Json::internalGet(bool*) const { if (isBoolean()) { return true; } else { throw std::domain_error("This method only applies to boolean type"); } }
String AudioPluginInstance::Parameter::getText (float value, int maximumStringLength) const { if (isBoolean()) return value < 0.5f ? TRANS("Off") : TRANS("On"); return String (value).substring (0, maximumStringLength); }
const Boolean& Value::toBoolean() const { if (not isBoolean()) { throw utils::CastError(_("Value is not a boolean")); } return static_cast<const Boolean&>(*this); }
int isBoolean(struct a_NODE *node) { if(!node) // testa se é nulo return FALSE; if(node->token == LIT_TRUE || node->token == LIT_FALSE) // testa os literais return TRUE; if(node->token == TK_IDENTIFIER && node->node->dataType == ID_BOOL) // testa variável return TRUE; if(node->token == POINTER) // testa ponteiro return TRUE; if(node->token == FUNCALL && (node->sons[0]->node->dataType == ID_WORD || node->sons[0]->node->dataType == ID_BYTE)) // testa se é função return FALSE; if(node->token == FUNCALL && node->sons[0]->node->dataType == ID_BOOL) return TRUE; if(node->token == VECCALL && node->sons[0]->node->dataType == ID_WORD) // testa vetor return FALSE; if(node->token == VECCALL && node->sons[0]->node->dataType == ID_BYTE) // testa vetor return FALSE; if(node->token == VECCALL && node->sons[0]->node->dataType == ID_BOOL) // testa vetor return TRUE; if(node->token == '+' || node->token == '-' || node->token == '*' || node->token == '/') // testa os operadores que retornam inteiro return FALSE; if(node->token == EQ || node->token == NE || node->token == GE || node->token == LE || node->token == '>' || node->token == '<') // testa os operadores que retornam booleano return TRUE; if(isBoolean(node->sons[0])) return TRUE; if(isBoolean(node->sons[0]) && isBoolean(node->sons[1])) // testa os filhos return TRUE; return FALSE; }
JSObject* JSValue::synthesizePrototype(ExecState* exec) const { ASSERT(!isCell()); if (isNumber()) return exec->lexicalGlobalObject()->numberPrototype(); if (isBoolean()) return exec->lexicalGlobalObject()->booleanPrototype(); JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull()); exec->setException(exception); return new (exec) JSNotAnObject(exec, exception); }
int testArguments(struct HNODE *node1, struct a_NODE *node2) { int argNumber =1; struct intList * aux; struct a_NODE * aux2; aux = node1->args; aux2 = node2; while(aux || aux2) { if(!aux && aux2) { hasError++;{hasError++;printf("Semantic error: wrong number of arguments(given %d, should be less) on function call on line %d\n",argNumber,aux2->lineNumber);} return FALSE; } else if(aux && !aux2) { hasError++;{hasError++;printf("Semantic error: wrong number of arguments(given %d, should be more) on function call\n",argNumber-1);} return FALSE; } else if(aux->v == KW_BOOL) { if(!isBoolean(aux2->sons[0])) { hasError++;{hasError++;printf("Semantic error: argument of number %d is of wrong type(should be boolean) on line %d\n",argNumber,aux2->lineNumber);} return FALSE; } else { argNumber++; aux = aux->next; aux2 = aux2->sons[1]; } } else if(aux->v == KW_WORD || aux->v == KW_BYTE) { if(!isInt(aux2->sons[0])) { hasError++;{hasError++;printf("Semantic error: argument number %d is of wrong type(should be integer) on line %d\n",argNumber,aux2->lineNumber);} return FALSE; } else { argNumber++; aux = aux->next; aux2 = aux2->sons[1]; } } } return TRUE; }
JSObject* JSImmediate::prototype(JSValue* v, ExecState* exec) { ASSERT(isImmediate(v)); if (isNumber(v)) return exec->lexicalGlobalObject()->numberPrototype(); if (isBoolean(v)) return exec->lexicalGlobalObject()->booleanPrototype(); JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, v->isNull()); exec->setException(exception); return new (exec) JSNotAnObject(exec, exception); }
JSObject* JSImmediate::toObject(JSValue* v, ExecState* exec) { ASSERT(isImmediate(v)); if (isNumber(v)) return constructNumberFromImmediateNumber(exec, v); if (isBoolean(v)) return constructBooleanFromImmediateBoolean(exec, v); JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, v->isNull()); exec->setException(exception); return new (exec) JSNotAnObject(exec, exception); }
JSObject* JSValue::synthesizeObject(ExecState* exec) const { ASSERT(!isCell()); if (isNumber()) return constructNumber(exec, asValue()); if (isBoolean()) return constructBooleanFromImmediateBoolean(exec, asValue()); JSNotAnObjectErrorStub* exception = createNotAnObjectErrorStub(exec, isNull()); exec->setException(exception); return new (exec) JSNotAnObject(exec, exception); }
std::optional<double> JSValue::toNumberFromPrimitive() const { if (isEmpty()) return std::nullopt; if (isNumber()) return asNumber(); if (isBoolean()) return asBoolean(); if (isUndefined()) return PNaN; if (isNull()) return 0; return std::nullopt; }
float AudioPluginInstance::Parameter::getValueForText (const String& text) const { auto floatValue = text.retainCharacters ("-0123456789.").getFloatValue(); if (isBoolean()) { if (onStrings.contains (text, true)) return 1.0f; if (offStrings.contains (text, true)) return 0.0f; return floatValue < 0.5f ? 0.0f : 1.0f; } return floatValue; }
JSObject *JSImmediate::toObject(const JSValue *v, ExecState *exec) { assert(isImmediate(v)); if (v == jsNull()) { return throwError(exec, TypeError, "Null value"); } else if (v == jsUndefined()) { return throwError(exec, TypeError, "Undefined value"); } else if (isBoolean(v)) { List args; args.append(const_cast<JSValue *>(v)); return exec->lexicalInterpreter()->builtinBoolean()->construct(exec, args); } else { ASSERT(isNumber(v)); List args; args.append(const_cast<JSValue *>(v)); return exec->lexicalInterpreter()->builtinNumber()->construct(exec, args); } }
JSObject* JSValue::synthesizePrototype(ExecState* exec) const { VM& vm = exec->vm(); auto scope = DECLARE_THROW_SCOPE(vm); if (isCell()) { if (isString()) return exec->lexicalGlobalObject()->stringPrototype(); ASSERT(isSymbol()); return exec->lexicalGlobalObject()->symbolPrototype(); } if (isNumber()) return exec->lexicalGlobalObject()->numberPrototype(); if (isBoolean()) return exec->lexicalGlobalObject()->booleanPrototype(); ASSERT(isUndefinedOrNull()); throwException(exec, scope, createNotAnObjectError(exec, *this)); return nullptr; }
bool VirtualValue::operator>=(const VirtualValue& that) const { ASSERT(!isArray() && !isObject() && !isBoolean()); ASSERT(mKind == that.mKind); switch ( mKind ) { case eNumber: return asNumber() >= that.asNumber(); case eReal: return asReal() >= that.asReal(); case eChar: return asChar() >= that.asChar(); case eString: return asString() >= that.asString(); } return false; }
//returns the token type of next token and corresponding string is stored in tokenString TokenType getToken(){ TokenType currentToken = OTHER; char ch; int saveCharInToken = 1; StateType state = START; int tokenStringIndex = 0; bzero(tokenString, MAX_STR_LEN); while(state != END){ ch = getNextChar(); switch(state){ case START : if(isdigit(ch)){ if(ch == '0') state = INT; else state = INT_DEC; } else if(ch == '\'') state = CHAR; else if(ch == '\"') state = STRING; else if(ch == '_' || isalpha(ch)) state = ID; else if(ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '%') state = OP; else if(ch == '<' || ch == '>' || ch == '=' || ch == '!') state = OP; else if(ch == '&' || ch == '|') state = COND_OP; else if(ch == '[' || ch == ']' || ch == '{' || ch == '}' || ch == '(' || ch == ')' || ch == ',' || ch == ';') state = DELIMIT; else if(isWhiteSpace(ch)) continue; else{ handleTokenError(ch, 0, 0); currentToken = OTHER; state = END; saveCharInToken = 0; } break; case INT : if(ch == 'x') state = INT_EXPECT_HEX; else if(isdigit(ch)) state = INT_DEC; else { state = END; currentToken = INTLITERAL; saveCharInToken = 0; ungetNextChar(); } break; case INT_DEC : if(!isdigit(ch)) { state = END; currentToken = INTLITERAL; saveCharInToken = 0; ungetNextChar(); } break; case INT_EXPECT_HEX : if(isxdigit(ch)) state = INT_HEX; else { handleTokenError(ch, 0, 0); currentToken = ERROR; } break; case INT_HEX : if(!isxdigit(ch)) { state = END; currentToken = INTLITERAL; saveCharInToken = 0; ungetNextChar(); } break; case CHAR : if(ch >= 32 && ch <= 126 && ch != '\'' && ch != '\"' && ch != '\\') state = CHAR_EXPECT_QUOTE; else if(ch == '\\') state = ESCAPE_CHAR; else { handleTokenError(ch, 0, 0); state = CHAR_EXPECT_QUOTE; currentToken = ERROR; } break; case CHAR_EXPECT_QUOTE : if(ch == '\'') { state = END; if(currentToken != ERROR) currentToken = CHARLITERAL; saveCharInToken = 1; } else { handleTokenError(ch, 1, '\''); currentToken = ERROR; } break; case ESCAPE_CHAR : if(ch == 'n' || ch == 't' || ch == '\'' || ch == '\"' || ch == '\\') state = CHAR_EXPECT_QUOTE; else { handleTokenError(ch, 0, 0); state = CHAR_EXPECT_QUOTE; currentToken = ERROR; } break; case STRING : if(ch == '\\') state = STRING_ESCAPE_CHAR; else if(ch == '\"'){ state = END; if(currentToken != ERROR) currentToken = STRINGLITERAL; saveCharInToken = 1; } else if(!(ch >= 32 && ch <= 126 && ch != '\'' && ch != '\\')) { handleTokenError(ch, 1, '\"'); currentToken = ERROR; state = END; } break; case STRING_ESCAPE_CHAR : if(ch == 'n' || ch == 't' || ch == '\'' || ch == '\"' || ch == '\\') state = STRING; else { handleTokenError(ch, 0, 0); state = STRING; currentToken = ERROR; } break; case ID : if(!isalnum(ch) && ch != '_') { state = END; currentToken = IDENTIFIER; saveCharInToken = 0; ungetNextChar(); } break; case OP : if(tokenString[0] == '/' && ch == '/') { state = COMMENT; currentToken = COMMENT_TOK; } else if(ch == '=') { state = END; currentToken = OPERATOR; saveCharInToken = 1; } else{ state = END; currentToken = OPERATOR; saveCharInToken = 0; ungetNextChar(); } break; case COND_OP : if(ch == tokenString[0]) { state = END; currentToken = OPERATOR; saveCharInToken = 1; } else { handleTokenError(ch, 1, tokenString[0]); currentToken = ERROR; } break; case COMMENT : if(ch == '\n') { state = END; saveCharInToken = 0; ungetNextChar(); } break; case DELIMIT : state = END; currentToken = DELIMITER; saveCharInToken = 0; ungetNextChar(); } if(ch == EOF) break; if(saveCharInToken && currentToken != ERROR) tokenString[tokenStringIndex++] = ch; //printf("ch = %c\tsave = %d\tstate = %s\ttoken = %s\ttokenString = %s\n", ch, saveCharInToken, stateTypeStr[state], tokenTypeStr[currentToken], tokenString); } tokenString[tokenStringIndex] = '\0'; if(currentToken == COMMENT_TOK) return getToken(); if(currentToken == IDENTIFIER && isBoolean(tokenString)) currentToken = BOOLEANLITERAL; else if(currentToken == IDENTIFIER && isKeyword(tokenString)) currentToken = KEYWORD; return currentToken; }
BooleanType::BooleanType(const Type& t) throw(IllegalArgumentException) : Type(t) { PrettyCheckArgument(isNull() || isBoolean(), this); }
void verify(struct a_NODE * node_p) { struct a_NODE * aux; if(node_p) { struct a_NODE node_ = *node_p; switch(node_.token) { // TOKENS case LIT_TRUE: break; case LIT_FALSE: break; case LIT_INTEGER: break; case TK_IDENTIFIER: break; case LIT_CHAR: break; case LIT_STRING: break; // LIST case LIST: verify((node_.sons[0])); verify((node_.sons[1])); break; // TYPE case KW_BOOL: break; case KW_WORD: break; case KW_BYTE: break; // FUNC_DECLARATION case ARGUMENTS: verify((node_.sons[0])); verify((node_.sons[1])); if((node_.sons[2])!=NULL) { verify((node_.sons[2])); } break; case D_NODE: // GAMBIARRATION verify((node_.sons[0])); verify((node_.sons[1])); break; case FUNC_DECLARATION: /*node_.sons[1]->node->type = ID_FUNC; if(node_.sons[0]->token == KW_BOOL) node_.sons[1]->node->dataType = ID_BOOL; else if(node_.sons[0]->token == KW_WORD) node_.sons[1]->node->dataType = ID_WORD; else if(node_.sons[0]->token == KW_BYTE) node_.sons[1]->node->dataType = ID_BYTE; currentFunction = node_.sons[1]->node; aux = node_.sons[2]; for(aux = node_.sons[2] ; aux != NULL ; aux = aux->sons[2]) { aux->sons[1]->node->type = ID_SCALAR; if(aux->sons[0]->token == KW_BOOL) { aux->sons[1]->node->dataType = ID_BOOL; } else if(aux->sons[0]->token == KW_WORD) { aux->sons[1]->node->dataType = ID_WORD; } else if(aux->sons[0]->token == KW_BYTE) { aux->sons[1]->node->dataType = ID_BYTE; } node_.sons[1]->node->args = insertInIntList(aux->sons[0]->token,node_.sons[1]->node->args); } */ currentFunction = node_.sons[1]->node; verify((node_.sons[3])); // SEMPRE D_NODE , GAMBIARRATIONN break; // DECLARATIONS case PROG: verify((node_.sons[0])); verify((node_.sons[1])); break; case DECLARATION: if(node_.sons[1]->node->type != SYMBOL_IDENTIFIER) {hasError++;printf("Semantic error on line %d: variable %s already declared \n",node_.lineNumber,node_.sons[1]->node->value);} else { if(node_.sons[0]->token == KW_BOOL) node_.sons[1]->node->dataType = ID_BOOL; else if(node_.sons[0]->token == KW_WORD) node_.sons[1]->node->dataType = ID_WORD; else if(node_.sons[0]->token == KW_BYTE) node_.sons[1]->node->dataType = ID_BYTE; node_.sons[1]->node->type = ID_SCALAR; if(!( (node_.sons[0]->token == KW_BOOL && (node_.sons[2]->token == LIT_TRUE || node_.sons[2]->token == LIT_FALSE)) || (((node_.sons[0]->token == KW_WORD) || (node_.sons[0]->token == KW_BYTE)) && ((node_.sons[2]->token == LIT_INTEGER)||(node_.sons[2]->token == LIT_CHAR))))) {hasError++;printf("Semantic error on line %d: Scalar initialized wrong.\n",node_.lineNumber);} } break; case DECLARATION_POINTER: if(node_.sons[1]->node->type != SYMBOL_IDENTIFIER) {hasError++;printf("Semantic error on line %d: variable already declared\n",node_.lineNumber);} else { if(node_.sons[0]->token == KW_BOOL) node_.sons[1]->node->dataType = ID_BOOL; else if(node_.sons[0]->token == KW_WORD) node_.sons[1]->node->dataType = ID_WORD; else if(node_.sons[0]->token == KW_BYTE) node_.sons[1]->node->dataType = ID_BYTE; node_.sons[1]->node->type = ID_POINTER; } break; case DECLARATION_VEC: if(node_.sons[1]->node->type != SYMBOL_IDENTIFIER) {hasError++;printf("Semantic error on line %d: variable already declared\n",node_.lineNumber);} else { if(node_.sons[0]->token == KW_BOOL) node_.sons[1]->node->dataType = ID_BOOL; else if(node_.sons[0]->token == KW_WORD) node_.sons[1]->node->dataType = ID_WORD; else if(node_.sons[0]->token == KW_BYTE) node_.sons[1]->node->dataType = ID_BYTE; node_.sons[1]->node->type = ID_VECTOR; if(!isInt(node_.sons[2])) {hasError++;printf("Semantic error on line %d: Vector with not-integer size\n",node_.lineNumber);} } break; case DECLARATION_VEC_INIT: if(node_.sons[1]->node->type != SYMBOL_IDENTIFIER) {hasError++;printf("Semantic error on line %d: variable already declared\n",node_.lineNumber);} else { if(node_.sons[0]->token == KW_BOOL) node_.sons[1]->node->dataType = ID_BOOL; else if(node_.sons[0]->token == KW_WORD) node_.sons[1]->node->dataType = ID_WORD; else if(node_.sons[0]->token == KW_BYTE) node_.sons[1]->node->dataType = ID_BYTE; node_.sons[1]->node->type = ID_VECTOR; if(!isInt(node_.sons[2])) {hasError++;printf("Semantic error on line %d: Vector with not-integer size\n",node_.lineNumber);} if(!(node_.sons[3]->token == LIST)) {hasError++;printf("Semantic error on line %d: Vector initialized wrong.\n",node_.lineNumber);} } break; // EXPRESSION case '&': if(!(node_.sons[0]->node->type==ID_SCALAR)) {hasError++;printf("Semantic error: getting reference for not-scalar on line %d\n",node_.lineNumber);} verify(node_.sons[0]); break; case POINTER: if(!(node_.sons[0]->node->type==ID_POINTER)) {hasError++;printf("Semantic error: using not-pointer as pointer on line %d\n",node_.lineNumber);} verify(node_.sons[0]); break; case '*': if(!(isInt(node_.sons[0]) && isInt(node_.sons[1]))) {hasError++;printf("Semantic error: multiplying not integer on line %d\n",node_.lineNumber);} verify(node_.sons[0]); verify(node_.sons[1]); break; case '(': verify((node_.sons[0])); break; case '+': if(!(isInt(node_.sons[0]) && isInt(node_.sons[1]))) {hasError++;printf("Semantic error: adding not integer on line %d\n",node_.lineNumber);} verify(node_.sons[0]); verify(node_.sons[1]); break; case '-': if(!(isInt(node_.sons[0]) && isInt(node_.sons[1]))) {hasError++;printf("Semantic error: subtracting not integer on line %d\n",node_.lineNumber);} verify(node_.sons[0]); verify(node_.sons[1]); break; case '/': if(!(isInt(node_.sons[0]) && isInt(node_.sons[1]))) {hasError++;printf("Semantic error: dividing not integer on line %d\n",node_.lineNumber);} verify(node_.sons[0]); verify(node_.sons[1]); break; case OR: if(!(isBoolean(node_.sons[0]) && isBoolean(node_.sons[1]))) {hasError++;printf("Semantic error: '||' with not boolean on line %d\n",node_.lineNumber);} verify(node_.sons[0]); verify(node_.sons[1]); break; case AND: if(!(isBoolean(node_.sons[0]) && isBoolean(node_.sons[1]))) {hasError++;printf("Semantic error: '&&' with not boolean on line %d\n",node_.lineNumber);} verify(node_.sons[0]); verify(node_.sons[1]); break; case LE: verify(node_.sons[0]); verify(node_.sons[1]); break; case EQ: verify(node_.sons[0]); verify(node_.sons[1]); break; case GE: verify(node_.sons[0]); verify(node_.sons[1]); break; case NE: verify(node_.sons[0]); verify(node_.sons[1]); break; case '>': if(!(isInt(node_.sons[0]) && isInt(node_.sons[1]))) {hasError++;printf("Semantic error: '>' with not integer on line %d\n",node_.lineNumber);} verify(node_.sons[0]); verify(node_.sons[1]); break; case '<': if(!(isInt(node_.sons[0]) && isInt(node_.sons[1]))) {hasError++;printf("Semantic error: '<' with not integer on line %d\n",node_.lineNumber);} verify(node_.sons[0]); verify(node_.sons[1]); break; case VECCALL: if(node_.sons[0]->node->type == SYMBOL_IDENTIFIER) {hasError++;printf("Semantic error: Vector %s not declared used on line %d\n",node_.sons[0]->node->value,node_.lineNumber);} if(!isInt(node_.sons[1])) {hasError++;printf("Semantic error: Vector index not integer on line %d\n",node_.lineNumber);} if(!(node_.sons[0]->node->type==ID_VECTOR)) {hasError++;printf("Semantic error: Something not-vector used as vector on line %d\n",node_.lineNumber);} break; case NORMAL: if(node_.sons[0]->node->type == SYMBOL_IDENTIFIER) {hasError++;printf("Semantic error: Variable %s not declared used on line %d\n",node_.sons[0]->node->value,node_.lineNumber);} if(node_.sons[0]->node->type != ID_SCALAR && node_.sons[0]->node->type != ID_POINTER) {hasError++;printf("Semantic error: Something not-scalar used as scalar on line %d\n",node_.lineNumber);} break; // FUNCALL ARGCALL CMD_SEQ case FUNCALL: if(node_.sons[0]->node->type == SYMBOL_IDENTIFIER) {hasError++;printf("Semantic error: Function %s not yet declared used on line %d\n",node_.sons[0]->node->value,node_.lineNumber);} if(!(node_.sons[0]->node->type==ID_FUNC)) {hasError++;printf("Semantic error: Something not-function used as function on line %d\n",node_.lineNumber);} testArguments(node_.sons[0]->node,node_.sons[1]); break; case ARGCALL: break; case CMD_SEQ: verify((node_.sons[0])); verify((node_.sons[1])); break; // OUTPUT case OUTPUT_L: verify(node_.sons[0]); verify(node_.sons[1]); break; // CMD case INPUT: verify(node_.sons[0]); break; case OUTPUT: verify(node_.sons[0]); break; case RETURN: if(!currentFunction) {hasError++;printf("Semantic error: 'return' in wrong place on line %d\n",node_.lineNumber);} else if(currentFunction->dataType == ID_WORD) { if(!isInt(node_.sons[0])) {hasError++;printf("Semantic error: wrong return type for function %s, on line %d\n",currentFunction->value,node_.lineNumber);} } else if(currentFunction->dataType == ID_BYTE) { if(!isInt(node_.sons[0])) {hasError++;printf("Semantic error: wrong return type for function %s, on line %d\n",currentFunction->value,node_.lineNumber);} } else if(currentFunction->dataType == ID_BOOL) { if(!isBoolean(node_.sons[0])) {hasError++;printf("Semantic error: wrong return type for function %s, should be boolean, on line %d\n",currentFunction->value,node_.lineNumber);} } break; case BLOCK: verify((node_.sons[0])); break; case '=': verify(node_.sons[1]); ////////////////////////////////////////////////////////////////////// REMEMBER if(node_.sons[0]->token == VECCALL) { if(!(node_.sons[0]->sons[0]->node->type == ID_VECTOR)) {hasError++;printf("Semantic error: not-vector used as vector on line %d\n",node_.lineNumber);} if(!isInt(node_.sons[0]->sons[1])) {hasError++;printf("Semantic error: vector index is not integer on line %d\n",node_.lineNumber);} if(node_.sons[0]->sons[0]->node->dataType == ID_WORD) { if(!isInt(node_.sons[1])) {hasError++;printf("Semantic error: atributing to integer vector from not-integer on line %d\n",node_.lineNumber);} } else if(node_.sons[0]->sons[0]->node->dataType == ID_BYTE) { if(!isInt(node_.sons[1])) {hasError++;printf("Semantic error: atributing to integer vector from not-integer on line %d\n",node_.lineNumber);} } else if(node_.sons[0]->sons[0]->node->dataType == ID_BOOL) { if(!isBoolean(node_.sons[1])) {hasError++;printf("Semantic error: atributing to boolean vector from not-boolean on line %d\n",node_.lineNumber);} } else {hasError++;printf("Semantic error: identifier %s not declared on line %d\n",node_.sons[0]->node->value,node_.lineNumber);} } else if(node_.sons[0]->token == POINTER) { if(node_.sons[0]->sons[0]->node->type != ID_POINTER) {hasError++;printf("Semantic error: dereferencing non-pointer on line %d\n",node_.lineNumber);} if(node_.sons[0]->sons[0]->node->dataType == ID_WORD) { if(!isInt(node_.sons[1])) {hasError++;printf("Semantic error: atributing to integer scalar from not-integer on line %d\n",node_.lineNumber);} } else if(node_.sons[0]->sons[0]->node->dataType == ID_BYTE) { if(!isInt(node_.sons[1])) {hasError++;printf("Semantic error: atributing to integer scalar from not-integer on line %d\n",node_.lineNumber);} } else if(node_.sons[0]->sons[0]->node->dataType == ID_BOOL) { if(!isBoolean(node_.sons[1])) {hasError++;printf("Semantic error: atributing to boolean scalar from not-boolean on line %d\n",node_.lineNumber);} } else {hasError++;printf("Semantic error: identifier %s not declared on line %d\n",node_.sons[0]->node->value,node_.lineNumber);} } else if(node_.sons[0]->node->type == ID_POINTER) { if(!isPt(node_.sons[1])) { {hasError++;printf("Semantic error: atributin a non-pointer to a pointer on line %d\n",node_.lineNumber);} } } else if(node_.sons[0]->node->type == ID_SCALAR) { if(node_.sons[0]->node->type == ID_VECTOR) {hasError++;printf("Semantic error: vector used as not-vector on line %d\n",node_.lineNumber);} if(node_.sons[0]->node->dataType == ID_WORD) { if(!isInt(node_.sons[1])) {hasError++;printf("Semantic error: atributing to integer scalar from not-integer on line %d\n",node_.lineNumber);} } else if(node_.sons[0]->node->dataType == ID_BYTE) { if(!isInt(node_.sons[1])) {hasError++;printf("Semantic error: atributing to integer scalar from not-integer on line %d\n",node_.lineNumber);} } else if(node_.sons[0]->node->dataType == ID_BOOL) { if(!isBoolean(node_.sons[1])) {hasError++;printf("Semantic error: atributing to boolean scalar from not-boolean on line %d\n",node_.lineNumber);} } else {hasError++;printf("Semantic error: identifier %s not declared on line %d\n",node_.sons[0]->node->value,node_.lineNumber);} } else { {hasError++;printf("Semantic error: atributing to non-variable on line %d\n",node_.lineNumber);} } break; case IF_THEN: if(!isBoolean(node_.sons[0])) {hasError++;printf("Semantic error: if called with not-boolean on line %d\n",node_.lineNumber);} verify(node_.sons[1]); break; case IF_THEN_ELSE: if(!isBoolean(node_.sons[0])) {hasError++;printf("Semantic error: if called with not-boolean on line %d\n",node_.lineNumber);} verify(node_.sons[1]); verify(node_.sons[2]); break; case LOOP : if(!isBoolean(node_.sons[0])) {hasError++;printf("Semantic error: loop called with not-boolean on line %d\n",node_.lineNumber);} verify(node_.sons[1]); break; // DEFAULT default: break; } // switch } // if node }
bool BooleanOrString::getAsBoolean() const { ASSERT(isBoolean()); return m_boolean; }
// parse the given parameter-value types void ParameterManager::parse(VParameterValue &vParameterValue) { // (1) checks if (m_mParameter.empty()) { BVC_ERROR << "no parameter definition found"; } // (2) read command line parameters for(VParameterValue::iterator it = vParameterValue.begin() ; it != vParameterValue.end() ; ++it) { // check if it is a valid parameter MParameter::iterator jt = m_mParameter.find((*it).strParameter); if (jt == m_mParameter.end()) { BVC_ERROR << "unrecognized parameter: " << (*it).strParameter; } // check that the parameter is assigned a value just once if (jt->second->strValue.compare("") != 0) { BVC_ERROR << "parameter " << (*it).strParameter << " defined multiple times"; } // keep the parameter value jt->second->strValue = (*it).strValue; } // (3) check that all the required command-line parameters receive a value for(MParameter::iterator it = m_mParameter.begin() ; it != m_mParameter.end() ; ++it) { // check value if (it->second->strValue.compare("") == 0) { if (it->second->bOptional == false) { BVC_ERROR << "undefined parameter " << it->first << " is required"; } else { it->second->strValue = it->second->strDefaultValue; } } else { // check type switch(it->second->iType) { case PARAMETER_TYPE_STRING: { break; } case PARAMETER_TYPE_BOOLEAN: { if (!isBoolean(it->second->strValue.c_str())) { BVC_ERROR << "parameter type mismatch: \"" << it->second->strName << " = " << it->second->strValue << "\""; } break; } case PARAMETER_TYPE_INTEGER: { if (!isInteger(it->second->strValue.c_str())) { BVC_ERROR << "parameter type mismatch: \"" << it->second->strName << " = " << it->second->strValue << "\""; } break; } case PARAMETER_TYPE_FLOAT: { if (!isFloat(it->second->strValue.c_str())) { BVC_ERROR << "parameter type mismatch: \"" << it->second->strName << " = " << it->second->strValue << "\""; } break; } case PARAMETER_TYPE_FILE: { break; } case PARAMETER_TYPE_FOLDER: { break; } } // check allowed values if (it->second->vAllowedValues != NULL) { bool bMatch = false; for(VString::iterator jt = it->second->vAllowedValues->begin() ; jt != it->second->vAllowedValues->end() ; ++jt) { if (it->second->strValue.compare(*jt) == 0) { bMatch = true; break; } } if (bMatch == false) { BVC_ERROR << "parameter " << it->second->strName << " receives an invalid value: \"" << it->second->strValue << "\""; } } // check allowed range if (it->second->allowedRange != NULL) { if (it->second->iType == PARAMETER_TYPE_INTEGER) { int iValue = atoi(it->second->strValue.c_str()); // if a minimum value is defined make the corresponding check if (it->second->allowedRange->strMinimumValue.compare("") != 0) { int iMinimumValue = atoi(it->second->allowedRange->strMinimumValue.c_str()); if (iValue < iMinimumValue) { BVC_ERROR << "parameter " << it->second->strName << " receives a value out of range: " << it->second->strValue.c_str(); } } // if a maximum value is defined make the corresponding check if (it->second->allowedRange->strMaximumValue.compare("") != 0) { int iMaximumValue = atoi(it->second->allowedRange->strMaximumValue.c_str()); if (iValue > iMaximumValue) { BVC_ERROR << "parameter " << it->second->strName << " receives a value out of range: " << it->second->strValue.c_str(); } } } else if (it->second->iType == PARAMETER_TYPE_FLOAT) { float fValue = (float)atof(it->second->strValue.c_str()); // if a minimum value is defined make the corresponding check if (it->second->allowedRange->strMinimumValue.compare("") != 0) { float fMinimumValue = (float)atof(it->second->allowedRange->strMinimumValue.c_str()); if (fValue < fMinimumValue) { BVC_ERROR << "parameter " << it->second->strName << " receives a value out of range"; } } // if a minimum value is defined make the corresponding check if (it->second->allowedRange->strMaximumValue.compare("") != 0) { float fMaximumValue = (float)atof(it->second->allowedRange->strMaximumValue.c_str()); if (fValue > fMaximumValue) { BVC_ERROR << "parameter " << it->second->strName << " receives a value out of range"; } } } else { assert(0); } } } } // (5) check incompatibilities for(VIncompatibility::iterator it = m_vIncompatibility.begin() ; it != m_vIncompatibility.end() ; ++it) { // if one parameter is set, none of the others can be set bool bOneDefined = true; for(VString::iterator jt = (*it).vParameters->begin() ; jt != (*it).vParameters->end() ; ++jt) { if (m_mParameter[*jt]->strValue.compare("") != 0) { VString::iterator kt = jt; ++kt; for( ; kt != (*it).vParameters->end() ; ++kt) { if (m_mParameter[*kt]->strValue.compare("") != 0) { BVC_ERROR << "parameters " << *jt << " and " << *kt << " cannot be simultaneously defined"; } } } } if (((*it).bOneRequired) && (bOneDefined == false)) { string str = "one of these parameters needs to be defined:"; for(VString::iterator jt = (*it).vParameters->begin() ; jt != (*it).vParameters->end() ; ++jt) { str += " " + *jt; } BVC_ERROR << str; } } // (6) check dependencies for(VDependency::iterator it = m_vDependency.begin() ; it != m_vDependency.end() ; ++it) { // find the parameter if (m_mParameter[(*it).strParameter]->strValue.compare("") == 0) { continue; } bool bDependencyMet = false; for(VParameterValue::iterator kt = (*it).vParameterValue.begin() ; kt != (*it).vParameterValue.end() ; ++kt ) { if (m_mParameter[(*kt).strParameter]->strValue.compare((*kt).strValue) != 0) { bDependencyMet = true; break; } } if (bDependencyMet == false) { stringstream oss; oss << "parameter: " << (*it).strParameter << " cannot be defined unless one of the following parameters is defined: " << endl; for(VParameterValue::iterator kt = (*it).vParameterValue.begin() ; kt != (*it).vParameterValue.end() ; ++kt ) { oss << (*kt).strParameter.c_str() << "(" << (*kt).strValue.c_str() << ")" << endl; } BVC_ERROR << oss; } } }
bool Utility::stringToBool(string str) { assert(isBoolean(str)); return toLower(str) == "true"; }
type typecheck(expr *e) { if(isBoolean(e)){return TY_BOOLEAN;} else if(isInteger(e)){return TY_INTEGER;} else{error("Type mismatch error");} }
Variant HHVM_FUNCTION(proc_open, const String& cmd, const Array& descriptorspec, VRefParam pipesParam, const Variant& cwd /* = uninit_variant */, const Variant& env /* = uninit_variant */, const Variant& other_options /* = uninit_variant */) { if (RuntimeOption::WhitelistExec && !check_cmd(cmd.data())) { return false; } if (cmd.size() != strlen(cmd.c_str())) { raise_warning("NULL byte detected. Possible attack"); return false; } Variant pipes(pipesParam, Variant::WithRefBind{}); std::vector<DescriptorItem> items; std::string scwd = ""; if (!cwd.isNull() && cwd.isString() && !cwd.asCStrRef().empty()) { scwd = cwd.asCStrRef().c_str(); } else if (!g_context->getCwd().empty()) { scwd = g_context->getCwd().c_str(); } Array enva; if (env.isNull()) { if (is_cli_mode()) { enva = cli_env(); } else { // Build out an environment that conceptually matches what we'd // see if we were to iterate the environment and call getenv() // for each name. // Env vars defined in the hdf file go in first for (const auto& envvar : RuntimeOption::EnvVariables) { enva.set(String(envvar.first), String(envvar.second)); } // global environment overrides the hdf for (char **env = environ; env && *env; env++) { char *p = strchr(*env, '='); if (p) { String name(*env, p - *env, CopyString); String val(p + 1, CopyString); enva.set(name, val); } } } // and then any putenv() changes take precedence for (ArrayIter iter(g_context->getEnvs()); iter; ++iter) { enva.set(iter.first(), iter.second()); } } else { enva = env.toArray(); } #ifdef _WIN32 PROCESS_INFORMATION pi; HANDLE childHandle; STARTUPINFO si; BOOL newprocok; SECURITY_ATTRIBUTES security; DWORD dwCreateFlags = 0; char *command_with_cmd; UINT old_error_mode; char cur_cwd[MAXPATHLEN]; bool suppress_errors = false; bool bypass_shell = false; if (!other_options.isNull() && other_options.isArray()) { auto arr = other_options.asCArrRef(); if (arr.exists(String("suppress_errors", CopyString), true)) { auto v = arr[String("suppress_errors", CopyString)]; if ((v.isBoolean() && v.asBooleanVal()) || (v.isInteger() && v.asInt64Val())) { suppress_errors = true; } } if (arr.exists(String("bypass_shell", CopyString), true)) { auto v = arr[String("bypass_shell", CopyString)]; if ((v.isBoolean() && v.asBooleanVal()) || (v.isInteger() && v.asInt64Val())) { bypass_shell = true; } } } /* we use this to allow the child to inherit handles */ memset(&security, 0, sizeof(security)); security.nLength = sizeof(security); security.bInheritHandle = true; security.lpSecurityDescriptor = nullptr; memset(&si, 0, sizeof(si)); si.cb = sizeof(si); si.dwFlags = STARTF_USESTDHANDLES; si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); si.hStdError = GetStdHandle(STD_ERROR_HANDLE); if (!pre_proc_open(descriptorspec, items)) return false; /* redirect stdin/stdout/stderr if requested */ for (size_t i = 0; i < items.size(); i++) { switch (items[i].index) { case 0: si.hStdInput = items[i].childend; break; case 1: si.hStdOutput = items[i].childend; break; case 2: si.hStdError = items[i].childend; break; } } memset(&pi, 0, sizeof(pi)); if (suppress_errors) { old_error_mode = SetErrorMode( SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); } dwCreateFlags = NORMAL_PRIORITY_CLASS; if (!RuntimeOption::ServerExecutionMode()) { dwCreateFlags |= CREATE_NO_WINDOW; } char *envp = build_envp(enva); if (bypass_shell) { newprocok = CreateProcess( nullptr, strdup(cmd.c_str()), &security, &security, TRUE, dwCreateFlags, envp, scwd.c_str(), &si, &pi); } else { std::string command_with = "cmd.exe /c "; command_with += cmd.toCppString(); newprocok = CreateProcess( nullptr, strdup(command_with.c_str()), &security, &security, TRUE, dwCreateFlags, envp, scwd.c_str(), &si, &pi); } free(envp); if (suppress_errors) { SetErrorMode(old_error_mode); } if (newprocok == FALSE) { DWORD dw = GetLastError(); char* msg; FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&msg, 0, nullptr); /* clean up all the descriptors */ for (size_t i = 0; i < items.size(); i++) { CloseHandle(items[i].childend); if (items[i].parentend) { CloseHandle(items[i].parentend); } } raise_warning("CreateProcess failed, error code - %u: %s", dw, msg); LocalFree(msg); return false; } childHandle = pi.hProcess; DWORD child = pi.dwProcessId; CloseHandle(pi.hThread); return post_proc_open(cmd, pipes, enva, items, (pid_t)child, childHandle); #else pid_t child; if (LightProcess::Available()) { // light process available // there is no need to do any locking, because the forking is delegated // to the light process if (!pre_proc_open(descriptorspec, items)) return false; const int item_size = items.size(); std::vector<int> created; created.reserve(item_size); std::vector<int> intended; intended.reserve(item_size); for (int i = 0; i < item_size; i++) { const auto& item = items[i]; created.push_back(item.childend); intended.push_back(item.index); } std::vector<std::string> envs; for (ArrayIter iter(enva); iter; ++iter) { StringBuffer nvpair; nvpair.append(iter.first().toString()); nvpair.append('='); nvpair.append(iter.second().toString()); std::string tmp = nvpair.detach().c_str(); if (tmp.find('\n') == std::string::npos) { envs.push_back(tmp); } } child = LightProcess::proc_open(cmd.c_str(), created, intended, scwd.c_str(), envs); assert(child); return post_proc_open(cmd, pipes, enva, items, child); } else { /* the unix way */ Lock lock(DescriptorItem::s_mutex); if (!pre_proc_open(descriptorspec, items)) return false; child = fork(); if (child) { // the parent process return post_proc_open(cmd, pipes, enva, items, child); } } assert(child == 0); /* this is the child process */ /* close those descriptors that we just opened for the parent stuff, * dup new descriptors into required descriptors and close the original * cruft */ for (auto& item : items) { item.dupChild(); } if (scwd.length() > 0 && chdir(scwd.c_str())) { // chdir failed, the working directory remains unchanged } std::vector<String> senvs; // holding those char * char **envp = build_envp(enva, senvs); execle("/bin/sh", "sh", "-c", cmd.data(), nullptr, envp); free(envp); _exit(127); #endif }
bool MessageFormatter::mapArgs(std::vector<icu::Formattable>& types, std::vector<icu::UnicodeString>& names, const Array& args) { int32_t count = args.size(), arg_num = 0; types.resize(count); names.resize(count); auto idx_limit = args->iter_end(); for (auto idx = args->iter_begin(); idx != idx_limit; idx = args->iter_advance(idx), ++arg_num) { auto key = args->getKey(idx); icu::Formattable::Type type = icu::Formattable::kObject; // unknown if (key.isString()) { UErrorCode error = U_ZERO_ERROR; icu::UnicodeString key16(u16(key.toString(), error)); if (U_FAILURE(error)) { setError(U_ILLEGAL_ARGUMENT_ERROR, "Invalid UTF-8 data in argument key: '%s'", key.toString().c_str()); return false; } if (m_namedParts.find(key16) != m_namedParts.end()) { type = m_namedParts[key16]; } names[arg_num] = key16; } else { auto num = key.toInt64(); if (m_numericParts.find(num) != m_numericParts.end()) { type = m_numericParts[num]; } char buffer[12]; int32_t len = snprintf(buffer, sizeof(buffer), "%d", (int)num); UErrorCode error = U_ZERO_ERROR; icu::UnicodeString numName(u16(String(buffer, len, CopyString), error)); names[arg_num] = numName; } auto val = args->getValue(idx); icu::Formattable formattable; switch(type) { case icu::Formattable::kString: { string_val: UErrorCode error = U_ZERO_ERROR; icu::UnicodeString ustr(u16(val.toString(), error)); if (U_FAILURE(error)) { setError(error, "Invalid UTF-8 data in string argument: '%s'", val.toString().c_str()); return false; } formattable.adoptString(new icu::UnicodeString(ustr)); break; } case icu::Formattable::kDouble: formattable.setDouble(val.toDouble()); break; case icu::Formattable::kLong: formattable.setLong(val.toInt64()); break; case icu::Formattable::kInt64: formattable.setInt64(val.toInt64()); break; case icu::Formattable::kDate: formattable.setDate(VariantToMilliseconds(val)); break; default: // No context for arg, so make assupmtion based on value if (val.isDouble()) { formattable.setDouble(val.toDouble()); } else if (val.isNull() || val.isBoolean() || val.isInteger()) { formattable.setInt64(val.toInt64()); } else if (val.isString() || val.isObject()) { goto string_val; } else { setError(U_ILLEGAL_ARGUMENT_ERROR, "No strategy to convert the " "value given for the argument with key '%s' " "is available", val.toString().c_str()); return false; } } types[arg_num] = formattable; } return true; }
Bool isSelfEval(sExpression *exp){ return isNumber(exp) || isBoolean(exp) || isNull(exp) || isString(exp) || isPrimitiveProc(exp); }
bool StyleContext::evalStyle(FunctionID _id, StyleParamKey _key, StyleParam::Value& _val) { _val = none_type{}; JSScope jsScope(*m_jsContext); auto jsValue = jsScope.getFunctionResult(_id); if (!jsValue) { return false; } if (jsValue.isString()) { std::string value = jsValue.toString(); switch (_key) { case StyleParamKey::outline_style: case StyleParamKey::repeat_group: case StyleParamKey::sprite: case StyleParamKey::sprite_default: case StyleParamKey::style: case StyleParamKey::text_align: case StyleParamKey::text_repeat_group: case StyleParamKey::text_source: case StyleParamKey::text_source_left: case StyleParamKey::text_source_right: case StyleParamKey::text_transform: case StyleParamKey::texture: _val = value; break; case StyleParamKey::color: case StyleParamKey::outline_color: case StyleParamKey::text_font_fill: case StyleParamKey::text_font_stroke_color: { Color result; if (StyleParam::parseColor(value, result)) { _val = result.abgr; } else { LOGW("Invalid color value: %s", value.c_str()); } break; } default: _val = StyleParam::parseString(_key, value); break; } } else if (jsValue.isBoolean()) { bool value = jsValue.toBool(); switch (_key) { case StyleParamKey::interactive: case StyleParamKey::text_interactive: case StyleParamKey::visible: _val = value; break; case StyleParamKey::extrude: _val = value ? glm::vec2(NAN, NAN) : glm::vec2(0.0f, 0.0f); break; default: break; } } else if (jsValue.isArray()) { auto len = jsValue.getLength(); switch (_key) { case StyleParamKey::extrude: { if (len != 2) { LOGW("Wrong array size for extrusion: '%d'.", len); break; } double v1 = jsValue.getValueAtIndex(0).toDouble(); double v2 = jsValue.getValueAtIndex(1).toDouble(); _val = glm::vec2(v1, v2); break; } case StyleParamKey::color: case StyleParamKey::outline_color: case StyleParamKey::text_font_fill: case StyleParamKey::text_font_stroke_color: { if (len < 3 || len > 4) { LOGW("Wrong array size for color: '%d'.", len); break; } double r = jsValue.getValueAtIndex(0).toDouble(); double g = jsValue.getValueAtIndex(1).toDouble(); double b = jsValue.getValueAtIndex(2).toDouble(); double a = 1.0; if (len == 4) { a = jsValue.getValueAtIndex(3).toDouble(); } _val = ColorF(r, g, b, a).toColor().abgr; break; } default: break; } } else if (jsValue.isNumber()) { double number = jsValue.toDouble(); if (std::isnan(number)) { LOGD("duk evaluates JS method to NAN.\n"); } switch (_key) { case StyleParamKey::text_source: case StyleParamKey::text_source_left: case StyleParamKey::text_source_right: _val = doubleToString(number); break; case StyleParamKey::extrude: _val = glm::vec2(0.f, number); break; case StyleParamKey::placement_spacing: { _val = StyleParam::Width{static_cast<float>(number), Unit::pixel}; break; } case StyleParamKey::width: case StyleParamKey::outline_width: { // TODO more efficient way to return pixels. // atm this only works by return value as string _val = StyleParam::Width{static_cast<float>(number)}; break; } case StyleParamKey::angle: case StyleParamKey::priority: case StyleParamKey::text_priority: case StyleParamKey::text_font_stroke_width: case StyleParamKey::placement_min_length_ratio: { _val = static_cast<float>(number); break; } case StyleParamKey::size: { StyleParam::SizeValue vec; vec.x.value = static_cast<float>(number); _val = vec; break; } case StyleParamKey::order: case StyleParamKey::outline_order: case StyleParamKey::color: case StyleParamKey::outline_color: case StyleParamKey::text_font_fill: case StyleParamKey::text_font_stroke_color: { _val = static_cast<uint32_t>(number); break; } default: break; } } else if (jsValue.isUndefined()) { // Explicitly set value as 'undefined'. This is important for some styling rules. _val = Undefined(); } else { LOGW("Unhandled return type from Javascript style function for %d.", _key); } return !_val.is<none_type>(); }
bool BooleanOrStringOrUnrestrictedDouble::getAsBoolean() const { DCHECK(isBoolean()); return m_boolean; }