Expression* Expression::convert( Type* a_pOutputType, int conversionType /*= e_implicit_conversion*/, LanguageElement* a_pContextScope ) const { if(a_pOutputType->removeQualifiers()->equals(m_pValueType->removeQualifiers()) && conversionType == e_implicit_conversion) return const_cast<Expression*>(this); conversion* conv = getValueType()->conversionTo(a_pOutputType, conversionType, a_pContextScope); if(conv == nullptr) return o_new(BuiltInConversionExpression)(const_cast<Expression*>(this), nullptr, conversionType); Expression* pConversion = conv->convert(const_cast<Expression*>(this)); o_assert(pConversion); delete conv; return pConversion; }
/* * Produce a debugging string describing an NValue. */ std::string NValue::debug() const { const ValueType type = getValueType(); if (isNull()) { return "<NULL>"; } std::ostringstream buffer; std::string out_val; const char* ptr; int64_t addr; buffer << getTypeName(type) << "::"; switch (type) { case VALUE_TYPE_BOOLEAN: buffer << (getBoolean() ? "true" : "false"); break; case VALUE_TYPE_TINYINT: buffer << static_cast<int32_t>(getTinyInt()); break; case VALUE_TYPE_SMALLINT: buffer << getSmallInt(); break; case VALUE_TYPE_INTEGER: buffer << getInteger(); break; case VALUE_TYPE_BIGINT: case VALUE_TYPE_TIMESTAMP: buffer << getBigInt(); break; case VALUE_TYPE_DOUBLE: buffer << getDouble(); break; case VALUE_TYPE_VARCHAR: ptr = reinterpret_cast<const char*>(getObjectValue_withoutNull()); addr = reinterpret_cast<int64_t>(ptr); out_val = std::string(ptr, getObjectLength_withoutNull()); buffer << "[" << getObjectLength_withoutNull() << "]"; buffer << "\"" << out_val << "\"[@" << addr << "]"; break; case VALUE_TYPE_VARBINARY: ptr = reinterpret_cast<const char*>(getObjectValue_withoutNull()); addr = reinterpret_cast<int64_t>(ptr); out_val = std::string(ptr, getObjectLength_withoutNull()); buffer << "[" << getObjectLength_withoutNull() << "]"; buffer << "-bin[@" << addr << "]"; break; case VALUE_TYPE_DECIMAL: buffer << createStringFromDecimal(); break; default: buffer << "(no details)"; break; } std::string ret(buffer.str()); return (ret); }
String Property::getStringFromValue() const { String rval; if (getValueType() == BoolType) { rval = Ogre::StringConverter::toString(boost::get<bool>(m_value)); } else if (getValueType() == IntType) { rval = Ogre::StringConverter::toString(boost::get<int>(m_value)); } else if (getValueType() == FloatType) { rval = Ogre::StringConverter::toString(boost::get<float>(m_value)); } else if (getValueType() == StringType) { rval = boost::get<String>(m_value); } else if (getValueType() == Vector3Type) { rval = Ogre::StringConverter::toString(boost::get<Vector3>(m_value)); } else if (getValueType() == QuaternionType) { rval = Ogre::StringConverter::toString(boost::get<Quaternion>(m_value)); } return rval; }
void Property::setValueFromString(const String& value) { if (getValueType() == BoolType) { m_value = Ogre::StringConverter::parseBool(value); } else if (getValueType() == IntType) { m_value = Ogre::StringConverter::parseInt(value); } else if (getValueType() == FloatType) { m_value = Ogre::StringConverter::parseReal(value); } else if (getValueType() == StringType) { m_value = value; } else if (getValueType() == Vector3Type) { m_value = Ogre::StringConverter::parseVector3(value); } else if (getValueType() == QuaternionType) { m_value = Ogre::StringConverter::parseQuaternion(value); } }
Domain * Domain::load(const llvm::Type &type, const std::vector<Domain*> &offsets) const { // Default implementation. Useful for non-array objects. CANAL_ASSERT(offsets.empty()); if (&type == &getValueType()) return clone(); else { Domain *result = mEnvironment.getConstructors().create(type); result->setTop(); return result; } }
Domain * Pointer::dereferenceAndMerge(const State &state) const { if (mTop) { const llvm::Type &elementType = *mType.getElementType(); Domain *result = mEnvironment.getConstructors().create(elementType); result->setTop(); return result; } Domain *mergedValue = NULL; PlaceTargetMap::const_iterator it = mTargets.begin(); for (; it != mTargets.end(); ++it) { if (it->second->mType != Target::Block) continue; const Domain *source = state.findBlock(*it->second->mTarget); CANAL_ASSERT(source); std::vector<Domain*> offsets; if (!it->second->mOffsets.empty()) { CANAL_ASSERT_MSG(Integer::Utils::getSet(*it->second->mOffsets[0]).mValues.size() == 1, "First offset is expected to be zero!"); CANAL_ASSERT_MSG(Integer::Utils::getSet(*it->second->mOffsets[0]).mValues.begin()->isMinValue(), "First offset is expected to be zero!"); offsets = std::vector<Domain*>(it->second->mOffsets.begin() + 1, it->second->mOffsets.end()); } Domain *loaded = source->load(*getValueType().getElementType(), offsets); if (mergedValue) { mergedValue->join(*loaded); delete loaded; } else mergedValue = loaded; } return mergedValue; }
template<> NValue NValue::callUnary<FUNC_VOLT_VALIDATE_POLYGON>() const { assert(getValueType() == VALUE_TYPE_GEOGRAPHY); if (isNull()) { return NValue::getNullValue(VALUE_TYPE_BOOLEAN); } // Be optimistic. bool returnval = true; // Extract the polygon and check its validity. Polygon poly; poly.initFromGeography(getGeographyValue()); if (!poly.IsValid() || isMultiPolygon(poly)) { returnval = false; } return ValueFactory::getBooleanValue(returnval); }
bool Parameters::loadParams(int argc, char ** argv) { // load params from commandline args //if( argc < 3 ) { // fprintf(stderr, "ERROR: No parameters. Use \"-config\" or \"-f\" to specify configuration file.\n"); // return false; //} bool load_from_file = false; std::set<std::string> setParams; int jumpBy = 0; for( int i = 1; i < argc; i += jumpBy ) { std::string param = argv[i]; if(param[0] != '-') { std::cerr << "Unknown parameter: " << param << std::endl; return false; } Utils::ltrim(param, "- "); // normalise parameter to long name param = normaliseParamName(param); // check if valid param name if(!isValidParamName(param)) { std::cerr << "Unknown param option \"" << param << "\"\n"; exit(EXIT_FAILURE); } setParams.insert(param); // needed to not overwrite param value if file is specified //if the parameter is of type booL no corresponding value if( getValueType(param) == kBoolValue ) { jumpBy = 1; assert(setParamValue(param, kTrueValue)); } else { //not of type bool so must have corresponding value assert(i+1 < argc); jumpBy = 2; std::string val = argv[i+1]; Utils::trim(val); if( param == "config" ) load_from_file = true; if(!setParamValue(param, val)) { std::cerr << "Invalid Param name->value " << param << "->" << val << std::endl; return false; } } } bool success = true; // load from file if specified if (load_from_file) success = loadParams(getParamValue("config"), setParams); return success; }
template<> NValue NValue::callUnary<FUNC_VOLT_POLYGON_INVALID_REASON>() const { assert(getValueType() == VALUE_TYPE_GEOGRAPHY); if (isNull()) { return NValue::getNullValue(VALUE_TYPE_VARCHAR); } // Extract the polygon and check its validity. std::stringstream msg; Polygon poly; poly.initFromGeography(getGeographyValue()); if (poly.IsValid(&msg)) { isMultiPolygon(poly, &msg); } std::string res (msg.str()); if (res.size() == 0) { res = std::string("Valid Polygon"); } return getTempStringValue(res.c_str(),res.length()); }
Domain & Domain::store(const Domain &value, const std::vector<Domain*> &offsets, bool overwrite) { CANAL_ASSERT(offsets.empty()); if (&getValueType() == &value.getValueType()) { if (overwrite) setBottom(); join(value); } else setTop(); return *this; }
SDTypeConstraint::SDTypeConstraint(Record *R) { OperandNo = R->getValueAsInt("OperandNum"); if (R->isSubClassOf("SDTCisVT")) { ConstraintType = SDTCisVT; x.SDTCisVT_Info.VT = getValueType(R->getValueAsDef("VT")); if (x.SDTCisVT_Info.VT == MVT::isVoid) { errs() << " Cannot use 'Void' as type to SDTCisVT\n"; abort(); } } else if (R->isSubClassOf("SDTCisPtrTy")) { ConstraintType = SDTCisPtrTy; } else if (R->isSubClassOf("SDTCisInt")) { ConstraintType = SDTCisInt; } else if (R->isSubClassOf("SDTCisFP")) { ConstraintType = SDTCisFP; } else if (R->isSubClassOf("SDTCisVec")) { ConstraintType = SDTCisVec; } else if (R->isSubClassOf("SDTCisSameAs")) { ConstraintType = SDTCisSameAs; x.SDTCisSameAs_Info.OtherOperandNum = R->getValueAsInt("OtherOperandNum"); } else if (R->isSubClassOf("SDTCisVTSmallerThanOp")) { ConstraintType = SDTCisVTSmallerThanOp; x.SDTCisVTSmallerThanOp_Info.OtherOperandNum = R->getValueAsInt("OtherOperandNum"); } else if (R->isSubClassOf("SDTCisOpSmallerThanOp")) { ConstraintType = SDTCisOpSmallerThanOp; x.SDTCisOpSmallerThanOp_Info.BigOperandNum = R->getValueAsInt("BigOperandNum"); } else if (R->isSubClassOf("SDTCisEltOfVec")) { ConstraintType = SDTCisEltOfVec; x.SDTCisEltOfVec_Info.OtherOperandNum = R->getValueAsInt("OtherOpNum"); } else if (R->isSubClassOf("SDTCisSubVecOfVec")) { ConstraintType = SDTCisSubVecOfVec; x.SDTCisSubVecOfVec_Info.OtherOperandNum = R->getValueAsInt("OtherOpNum"); } else { errs() << "Unrecognized SDTypeConstraint '" << R->getName() << "'!\n"; exit(1); } }
llvm::Constant *Generator::createString(const std::string &str) { auto iterator = constant_pool.find(str); if (iterator != constant_pool.end()) { return iterator->second; } auto array = llvm::ConstantDataArray::getString(mod->getContext(), str); auto global_variable = new llvm::GlobalVariable( *mod, llvm::ArrayType::get(llvm::Type::getInt8Ty(mod->getContext()), str.length() + 1), true, llvm::GlobalValue::PrivateLinkage, 0, ".str"); global_variable->setAlignment(1); global_variable->setInitializer(array); auto zero = llvm::ConstantInt::get(llvm::Type::getInt8Ty(mod->getContext()), 0); std::vector<llvm::Value *> indicies; indicies.push_back(zero); indicies.push_back(zero); auto result = llvm::ConstantExpr::getGetElementPtr( global_variable->getValueType(), global_variable, indicies); constant_pool[str] = result; return result; }
void Property::setQuaternionValue(const Quaternion& value) { mada_assert(getValueType() == QuaternionType); m_value = value; }
const Quaternion& Property::getQuaternionValue() const { mada_assert(getValueType() == QuaternionType); return boost::get<Quaternion>(m_value); }
void Property::setVector3Value(const Vector3& value) { mada_assert(getValueType() == Vector3Type); m_value = value; }
const Vector3& Property::getVector3Value() const { mada_assert(getValueType() == Vector3Type); return boost::get<Vector3>(m_value); }
void Property::setStringValue(const String& value) { mada_assert(getValueType() == StringType); m_value = value; }
bool Property::operator!=(const Vector3& value) const { mada_assert(getValueType() == Vector3Type); return boost::get<Vector3>(m_value) != value; }
ValueData::ValueDataPtr VKRecord::getValue() const { uint32_t length = getRawDataLength(); uint32_t offset = getDataOffset(); if (length > LARGE_DATA_SIZE + DB_DATA_SIZE) { throw RegistryParseException("Value size too large."); } RegistryByteBuffer * data = NULL; switch (getValueType()) { case ValueData::VALTYPE_BIN: case ValueData::VALTYPE_NONE: case ValueData::VALTYPE_SZ: case ValueData::VALTYPE_EXPAND_SZ: case ValueData::VALTYPE_MULTI_SZ: case ValueData::VALTYPE_LINK: case ValueData::VALTYPE_RESOURCE_LIST: case ValueData::VALTYPE_FULL_RESOURCE_DESCRIPTOR: case ValueData::VALTYPE_RESOURCE_REQUIREMENTS_LIST: if (length >= LARGE_DATA_SIZE) { uint32_t bufSize = length - LARGE_DATA_SIZE; data = new RegistryByteBuffer(new ByteBuffer(getData(DATA_OFFSET_OFFSET, bufSize), bufSize)); } else if (DB_DATA_SIZE < length && length < LARGE_DATA_SIZE) { std::auto_ptr< Cell > c(new Cell(_buf, offset)); if (c.get() == NULL) { throw RegistryParseException("Failed to create Cell for Value data."); } try { std::auto_ptr< DBRecord > db(c->getDBRecord()); if (db.get() == NULL) { throw RegistryParseException("Failed to create Cell for DBRecord."); } data = new RegistryByteBuffer(new ByteBuffer(db->getData(length), length)); } catch (RegistryParseException& ) { data = new RegistryByteBuffer(new ByteBuffer(c->getData(), length)); } } else { std::auto_ptr< Cell > c(new Cell(_buf, offset)); if (c.get() == NULL) { throw RegistryParseException("Failed to create Cell for Value data."); } ByteBuffer * byteBuffer = new ByteBuffer(c->getData(), length); data = new RegistryByteBuffer(byteBuffer); } break; case ValueData::VALTYPE_DWORD: case ValueData::VALTYPE_BIG_ENDIAN: data = new RegistryByteBuffer(new ByteBuffer(getData(DATA_OFFSET_OFFSET, 0x4), 0x4)); break; case ValueData::VALTYPE_QWORD: { std::auto_ptr< Cell > c(new Cell(_buf, offset)); if (c.get() == NULL) { throw RegistryParseException("Failed to create Cell for Value data."); } ByteBuffer * byteBuffer = new ByteBuffer(c->getData(), length); data = new RegistryByteBuffer(byteBuffer); } break; default: // Unknown registry type. Create an empty buffer. data = new RegistryByteBuffer(new ByteBuffer(0)); } return new ValueData(data, getValueType()); }
float Property::getFloatValue() const { mada_assert(getValueType() == FloatType); return boost::get<float>(m_value); }
void Property::setIntValue(int value) { mada_assert(getValueType() == IntType); m_value = value; }
int Property::getIntValue() const { mada_assert(getValueType() == IntType); return boost::get<int>(m_value); }
bool Property::operator!=(float value) const { mada_assert(getValueType() == FloatType); return boost::get<float>(m_value) != value; }
bool Property::getBoolValue() const { mada_assert(getValueType() == BoolType); return boost::get<bool>(m_value); }
bool Property::operator!=(const Quaternion& value) const { mada_assert(getValueType() == QuaternionType); return boost::get<Quaternion>(m_value) != value; }
bool Property::operator!=(int value) const { mada_assert(getValueType() == IntType); return boost::get<int>(m_value) != value; }
void Property::setFloatValue(float value) { mada_assert(getValueType() == FloatType); m_value = value; }
const String& Property::getStringValue() const { mada_assert(getValueType() == StringType); return boost::get<String>(m_value); }
void Property::setBoolValue(bool value) { mada_assert(getValueType() == BoolType); m_value = value; }
bool Property::operator!=(const String& value) const { mada_assert(getValueType() == StringType); return boost::get<String>(m_value) != value; }