void Structure::allocateRareData(JSGlobalData& globalData) { ASSERT(!typeInfo().structureHasRareData()); StructureRareData* rareData = StructureRareData::create(globalData, previous()); m_typeInfo = TypeInfo(typeInfo().type(), typeInfo().flags() | StructureHasRareData); m_previousOrRareData.set(globalData, this, rareData); }
llvm::Value* LivenessEmitter::emitIsLiveCall(const AST::Type* const type, llvm::Value* const value) { auto& module = irEmitter_.module(); // Call __islive method. if (type->isObject()) { TypeInfo typeInfo(module); if (!typeInfo.objectHasLivenessIndicator(*(type->getObjectType()))) { // Assume value is always live. return ConstantGenerator(module).getBool(true); } // Call __islive method. const auto methodName = module.getCString("__islive"); const auto functionType = type->getObjectType()->getFunction(methodName).type(); MethodInfo methodInfo(type, methodName, functionType, {}); const auto contextArg = RefPendingResult(value, type); CallEmitter callEmitter(irEmitter_); return callEmitter.emitDynamicMethodCall(methodInfo, contextArg, {}); } llvm_unreachable("Unknown __islive value type."); }
GenRet ArgSymbol::codegen() { GenInfo* info = gGenInfo; FILE* outfile = info->cfile; GenRet ret; if( outfile ) { QualifiedType qt = qualType(); ret.c = '&'; ret.c += cname; ret.isLVPtr = GEN_PTR; if (qt.isRef() && !qt.isRefType()) ret.chplType = getOrMakeRefTypeDuringCodegen(typeInfo()); else if (qt.isWideRef() && !qt.isWideRefType()) { Type* refType = getOrMakeRefTypeDuringCodegen(typeInfo()); ret.chplType = getOrMakeWideTypeDuringCodegen(refType); } /* // BHARSH TODO: Is this still necessary? if (q.isRef() && !q.isRefType()) { ret.c = cname; ret.isLVPtr = GEN_PTR; } else if(q.isWideRef() && !q.isWideRefType()) { ret.c = cname; ret.isLVPtr = GEN_WIDE_PTR; } else { ret.c = '&'; ret.c += cname; ret.isLVPtr = GEN_PTR; } */ } else { #ifdef HAVE_LLVM ret = info->lvt->getValue(cname); #endif } // BHARSH TODO: Is this still necessary? //if( requiresCPtr() ) { // // Don't try to use chplType. // ret.chplType = NULL; // ret = codegenLocalDeref(ret); //} //ret.chplType = this->type; return ret; }
SimulatorResourceModel::TypeInfo SimulatorResourceModel::getTypeInfo(const AttributeValueVariant &value) const { AttributeTypeVisitor typeVisitor; boost::apply_visitor(typeVisitor, value); SimulatorResourceModel::TypeInfo typeInfo(typeVisitor.m_type, typeVisitor.m_baseType, typeVisitor.m_depth); return typeInfo; }
void MetaInfoPrivate::parseNonQmlClassRecursively(const QMetaObject *qMetaObject) { Q_ASSERT_X(qMetaObject, Q_FUNC_INFO, "invalid QMetaObject"); QString typeName; int majorVersion = -1; int minorVersion = -1; typeInfo(qMetaObject, &typeName, &majorVersion, &minorVersion); if (typeName.isEmpty()) { qWarning() << "Meta type system: Registered class has no name."; return; } NodeMetaInfo existingInfo = m_q->nodeMetaInfo(typeName, majorVersion, minorVersion); if (existingInfo.isValid() && existingInfo.majorVersion() == majorVersion && existingInfo.minorVersion() == minorVersion) { return; } NodeMetaInfo nodeMetaInfo(*m_q); nodeMetaInfo.setType(typeName, majorVersion, minorVersion); parseProperties(nodeMetaInfo, qMetaObject); parseClassInfo(nodeMetaInfo, qMetaObject); QString superTypeName; int superTypeMajorVersion = -1; int superTypeMinorVersion = -1; if (qMetaObject->superClass()) { typeInfo(qMetaObject->superClass(), &superTypeName, &superTypeMajorVersion, &superTypeMinorVersion); nodeMetaInfo.setSuperClass(superTypeName, superTypeMajorVersion, superTypeMinorVersion); } if (debug) qDebug() << "adding non qml type" << nodeMetaInfo.typeName() << nodeMetaInfo.majorVersion() << nodeMetaInfo.minorVersion() << ", parent type" << superTypeName << superTypeMajorVersion << superTypeMinorVersion; m_q->addNodeInfo(nodeMetaInfo); if (const QMetaObject *superClass = qMetaObject->superClass()) parseNonQmlClassRecursively(superClass); }
string Stock::toString() const { std::stringstream os; string strip(", "); StockManager& sm = StockManager::instance(); StockTypeInfo typeInfo(sm.getStockTypeInfo(type())); os << "Stock(" << market() << strip << code() << strip << name() << strip << typeInfo.description() << strip << valid() << strip << startDatetime() << strip << lastDatetime() << ")"; return os.str(); }
int Table::__tostring(lua_State *L) { SLB_DEBUG_CALL; SLB_DEBUG_STACK(10,L,"Table::__tostring (%p)",this); int top = lua_gettop(L); lua_pushfstring(L, "Table(%p) [%s] with keys:", this, typeInfo().name()); for(Elements::iterator i = _elements.begin(); i != _elements.end(); ++i) { lua_pushfstring(L, "\n\t%s -> %p [%s]",i->first.c_str(), i->second.get(), i->second->typeInfo().name()); } lua_concat(L, lua_gettop(L) - top); return 1; }
void TypeDefaultGen::buildRefAssignment(par::ComplexType& _type, NaReTi::Module& _module) { TypeInfo typeInfo(_type, true); _module.m_functions.emplace_back(new Function(":=", typeInfo)); Function& func = *_module.m_functions.back(); auto& alloc = _module.getAllocator(); func.scope.m_variables.push_back(alloc.construct<VarSymbol>("_0", typeInfo)); func.scope.m_variables.push_back(alloc.construct<VarSymbol>("_1", typeInfo)); func.paramCount = 2; func.scope.emplace_back(alloc.construct<ASTOp>(InstructionType::Mov)); func.bIntrinsic = true; func.bInline = true; func.intrinsicType = Function::Assignment; }
/** Returns typeptr or NULL if value type is int and value is 0. * @return Converted typeptr or null */ void *Any::toTypePtr() const{ if (typeId == TypePtr) { return dPtr; } if (typeId == Int) { if (dInt == 0) { return 0; } else { CBEnchanted::instance()->errors->createError("Can't convert integer '"+boost::lexical_cast<string>(dInt)+"' to typepointer", "Only integer 0 can be converted to typepointer (NULL)"); } } FIXME("Unsupported cast %s => type pointer", typeInfo().name()); return 0; }
HKU_API std::ostream& operator <<(std::ostream &os, const Stock& stock) { string strip(", "); StockManager& sm = StockManager::instance(); StockTypeInfo typeInfo(sm.getStockTypeInfo(stock.type())); os << "Stock(" << stock.market() << strip << stock.code() << strip #if defined(BOOST_WINDOWS) && (PY_VERSION_HEX >= 0x03000000) << utf8_to_gb(stock.name()) << strip << utf8_to_gb(typeInfo.description()) << strip #else << stock.name() << strip << typeInfo.description() << strip #endif << stock.valid() << strip << stock.startDatetime() << strip << stock.lastDatetime() << ")"; return os; }
uint8_t Any::toByte() const { assert(!empty()); switch (type()) { case Any::Int: return ((uint8_t)getInt()); case Any::Float: return ((uint8_t)getFloat()); case Any::String: if (dString == 0) return 0; try { return boost::lexical_cast<uint8_t>(dString->str); } catch (boost::bad_lexical_cast &) { return 0; } } FIXME("Unsupported cast %s >= %s", typeInfo().name(), typeid(uint8_t).name()); return 0; }
int32_t Any::toInt() const { assert(!empty()); switch (type()) { case Any::Int: return getInt(); case Any::Float: return ((int32_t)(getFloat() + 0.5f)); case Any::String: if (dString == 0) return 0; try { std::string tmp = dString->str; boost::algorithm::trim(tmp); return boost::lexical_cast<int32_t>(tmp); } catch (boost::bad_lexical_cast &) { return 0; } } FIXME("Unsupported cast %s >= %s", typeInfo().name(), typeid(int32_t).name()); return 0; }
ISString Any::toString() const { assert(!empty()); try { switch (type()) { case Any::Int: { ISString i(boost::lexical_cast<string>(getInt())); i.requireEncoding(false); return i; } case Any::Float: { ISString i(boost::lexical_cast<string>(getFloat())); i.requireEncoding(false); return i; } case Any::String: return ISString(dString); } } catch (boost::bad_lexical_cast &) { return ISString(); } FIXME("Unsupported cast %s >= %s", typeInfo().name(), typeid(string).name()); return ISString(); }
bool QDeclarativeDirParser::parse() { if (_isParsed) return true; _isParsed = true; _errors.clear(); _plugins.clear(); _components.clear(); QTextStream stream(&_source); int lineNumber = 0; forever { ++lineNumber; const QString line = stream.readLine(); if (line.isNull()) break; QString sections[3]; int sectionCount = 0; int index = 0; const int length = line.length(); while (index != length) { const QChar ch = line.at(index); if (ch.isSpace()) { do { ++index; } while (index != length && line.at(index).isSpace()); } else if (ch == QLatin1Char('#')) { // recognized a comment break; } else { const int start = index; do { ++index; } while (index != length && !line.at(index).isSpace()); const QString lexeme = line.mid(start, index - start); if (sectionCount >= 3) { reportError(lineNumber, start, QLatin1String("unexpected token")); } else { sections[sectionCount++] = lexeme; } } } if (sectionCount == 0) { continue; // no sections, no party. } else if (sections[0] == QLatin1String("plugin")) { if (sectionCount < 2) { reportError(lineNumber, -1, QString::fromUtf8("plugin directive requires 2 arguments, but %1 were provided").arg(sectionCount + 1)); continue; } const Plugin entry(sections[1], sections[2]); _plugins.append(entry); } else if (sections[0] == QLatin1String("internal")) { if (sectionCount != 3) { reportError(lineNumber, -1, QString::fromUtf8("internal types require 2 arguments, but %1 were provided").arg(sectionCount + 1)); continue; } Component entry(sections[1], sections[2], -1, -1); entry.internal = true; _components.append(entry); } else if (sections[0] == QLatin1String("typeinfo")) { if (sectionCount != 2) { reportError(lineNumber, -1, QString::fromUtf8("typeinfo requires 1 argument, but %1 were provided").arg(sectionCount - 1)); continue; } #ifdef QT_CREATOR TypeInfo typeInfo(sections[1]); _typeInfos.append(typeInfo); #endif } else if (sectionCount == 2) { // No version specified (should only be used for relative qmldir files) const Component entry(sections[0], sections[1], -1, -1); _components.append(entry); } else if (sectionCount == 3) { const QString &version = sections[1]; const int dotIndex = version.indexOf(QLatin1Char('.')); if (dotIndex == -1) { reportError(lineNumber, -1, QLatin1String("expected '.'")); } else if (version.indexOf(QLatin1Char('.'), dotIndex + 1) != -1) { reportError(lineNumber, -1, QLatin1String("unexpected '.'")); } else { bool validVersionNumber = false; const int majorVersion = version.left(dotIndex).toInt(&validVersionNumber); if (validVersionNumber) { const int minorVersion = version.mid(dotIndex + 1).toInt(&validVersionNumber); if (validVersionNumber) { const Component entry(sections[0], sections[2], majorVersion, minorVersion); _components.append(entry); } } } } else { reportError(lineNumber, -1, QString::fromUtf8("a component declaration requires 3 arguments, but %1 were provided").arg(sectionCount + 1)); } } return hasError(); }
BOOL typeInfo::tiMergeToCommonParent(COMP_HANDLE CompHnd, typeInfo* pDest, const typeInfo* pSrc, bool* changed) { assert(pSrc->IsDead() || typeInfo::AreEquivalent(::NormaliseForStack(*pSrc), *pSrc)); assert(pDest->IsDead() || typeInfo::AreEquivalent(::NormaliseForStack(*pDest), *pDest)); // Merge the auxiliary information like "this" pointer tracking, etc... // Remember the pre-state, so we can tell if it changed. *changed = false; DWORD destFlagsBefore = pDest->m_flags; // This bit is only set if both pDest and pSrc have it set pDest->m_flags &= (pSrc->m_flags | ~TI_FLAG_THIS_PTR); // This bit is set if either pDest or pSrc have it set pDest->m_flags |= (pSrc->m_flags & TI_FLAG_UNINIT_OBJREF); // This bit is set if either pDest or pSrc have it set pDest->m_flags |= (pSrc->m_flags & TI_FLAG_BYREF_READONLY); // If the byref wasn't permanent home in both sides, then merge won't have the bit set pDest->m_flags &= (pSrc->m_flags | ~TI_FLAG_BYREF_PERMANENT_HOME); if (pDest->m_flags != destFlagsBefore) { *changed = true; } // OK the main event. Merge the main types if (typeInfo::AreEquivalent(*pDest, *pSrc)) { return (TRUE); } if (pDest->IsUnboxedGenericTypeVar() || pSrc->IsUnboxedGenericTypeVar()) { // Should have had *pDest == *pSrc goto FAIL; } if (pDest->IsType(TI_REF)) { if (pSrc->IsType(TI_NULL)) { // NULL can be any reference type return TRUE; } if (!pSrc->IsType(TI_REF)) { goto FAIL; } // Ask the EE to find the common parent, This always succeeds since System.Object always works CORINFO_CLASS_HANDLE pDestClsBefore = pDest->m_cls; pDest->m_cls = CompHnd->mergeClasses(pDest->GetClassHandle(), pSrc->GetClassHandle()); if (pDestClsBefore != pDest->m_cls) { *changed = true; } return TRUE; } else if (pDest->IsType(TI_NULL)) { if (pSrc->IsType(TI_REF)) // NULL can be any reference type { *pDest = *pSrc; *changed = true; return TRUE; } goto FAIL; } else if (pDest->IsType(TI_STRUCT)) { if (pSrc->IsType(TI_STRUCT) && CompHnd->areTypesEquivalent(pDest->GetClassHandle(), pSrc->GetClassHandle())) { return TRUE; } goto FAIL; } else if (pDest->IsByRef()) { return tiCompatibleWithByRef(CompHnd, *pSrc, *pDest); } #ifdef _TARGET_64BIT_ // On 64-bit targets we have precise representation for native int, so these rules // represent the fact that the ECMA spec permits the implicit conversion // between an int32 and a native int. else if (typeInfo::AreEquivalent(*pDest, typeInfo::nativeInt()) && pSrc->IsType(TI_INT)) { return TRUE; } else if (typeInfo::AreEquivalent(*pSrc, typeInfo::nativeInt()) && pDest->IsType(TI_INT)) { *pDest = *pSrc; *changed = true; return TRUE; } #endif // _TARGET_64BIT_ FAIL: *pDest = typeInfo(); return FALSE; }
/*! \a url is used for generating errors. */ bool QQmlDirParser::parse(const QString &source) { _errors.clear(); _plugins.clear(); _components.clear(); _scripts.clear(); _designerSupported = false; quint16 lineNumber = 0; bool firstLine = true; const QChar *ch = source.constData(); while (!ch->isNull()) { ++lineNumber; bool invalidLine = false; const QChar *lineStart = ch; scanSpace(ch); if (*ch == QLatin1Char('\n')) { ++ch; continue; } if (ch->isNull()) break; QString sections[4]; int sectionCount = 0; do { if (*ch == QLatin1Char('#')) { scanToEnd(ch); break; } const QChar *start = ch; scanWord(ch); if (sectionCount < 4) { sections[sectionCount++] = source.mid(start-source.constData(), ch-start); } else { reportError(lineNumber, start-lineStart, QLatin1String("unexpected token")); scanToEnd(ch); invalidLine = true; break; } scanSpace(ch); } while (*ch != QLatin1Char('\n') && !ch->isNull()); if (!ch->isNull()) ++ch; if (invalidLine) { reportError(lineNumber, 0, QStringLiteral("invalid qmldir directive contains too many tokens")); continue; } else if (sectionCount == 0) { continue; // no sections, no party. } else if (sections[0] == QLatin1String("module")) { if (sectionCount != 2) { reportError(lineNumber, 0, QStringLiteral("module identifier directive requires one argument, but %1 were provided").arg(sectionCount - 1)); continue; } if (!_typeNamespace.isEmpty()) { reportError(lineNumber, 0, QStringLiteral("only one module identifier directive may be defined in a qmldir file")); continue; } if (!firstLine) { reportError(lineNumber, 0, QStringLiteral("module identifier directive must be the first directive in a qmldir file")); continue; } _typeNamespace = sections[1]; } else if (sections[0] == QLatin1String("plugin")) { if (sectionCount < 2 || sectionCount > 3) { reportError(lineNumber, 0, QStringLiteral("plugin directive requires one or two arguments, but %1 were provided").arg(sectionCount - 1)); continue; } const Plugin entry(sections[1], sections[2]); _plugins.append(entry); } else if (sections[0] == QLatin1String("internal")) { if (sectionCount != 3) { reportError(lineNumber, 0, QStringLiteral("internal types require 2 arguments, but %1 were provided").arg(sectionCount - 1)); continue; } Component entry(sections[1], sections[2], -1, -1); entry.internal = true; _components.insertMulti(entry.typeName, entry); } else if (sections[0] == QLatin1String("singleton")) { if (sectionCount < 3 || sectionCount > 4) { reportError(lineNumber, 0, QStringLiteral("singleton types require 2 or 3 arguments, but %1 were provided").arg(sectionCount - 1)); continue; } else if (sectionCount == 3) { // handle qmldir directory listing case where singleton is defined in the following pattern: // singleton TestSingletonType TestSingletonType.qml Component entry(sections[1], sections[2], -1, -1); entry.singleton = true; _components.insertMulti(entry.typeName, entry); } else { // handle qmldir module listing case where singleton is defined in the following pattern: // singleton TestSingletonType 2.0 TestSingletonType20.qml int major, minor; if (parseVersion(sections[2], &major, &minor)) { const QString &fileName = sections[3]; Component entry(sections[1], fileName, major, minor); entry.singleton = true; _components.insertMulti(entry.typeName, entry); } else { reportError(lineNumber, 0, QStringLiteral("invalid version %1, expected <major>.<minor>").arg(sections[2])); } } } else if (sections[0] == QLatin1String("typeinfo")) { if (sectionCount != 2) { reportError(lineNumber, 0, QStringLiteral("typeinfo requires 1 argument, but %1 were provided").arg(sectionCount - 1)); continue; } #ifdef QT_CREATOR TypeInfo typeInfo(sections[1]); _typeInfos.append(typeInfo); #endif } else if (sections[0] == QLatin1String("designersupported")) { if (sectionCount != 1) reportError(lineNumber, 0, QStringLiteral("designersupported does not expect any argument")); else _designerSupported = true; } else if (sections[0] == QLatin1String("depends")) { if (sectionCount != 3) { reportError(lineNumber, 0, QStringLiteral("depends requires 2 arguments, but %1 were provided").arg(sectionCount - 1)); continue; } int major, minor; if (parseVersion(sections[2], &major, &minor)) { Component entry(sections[1], QString(), major, minor); entry.internal = true; _dependencies.insert(entry.typeName, entry); } else { reportError(lineNumber, 0, QStringLiteral("invalid version %1, expected <major>.<minor>").arg(sections[2])); } } else if (sectionCount == 2) { // No version specified (should only be used for relative qmldir files) const Component entry(sections[0], sections[1], -1, -1); _components.insertMulti(entry.typeName, entry); } else if (sectionCount == 3) { int major, minor; if (parseVersion(sections[1], &major, &minor)) { const QString &fileName = sections[2]; if (fileName.endsWith(QLatin1String(".js"))) { // A 'js' extension indicates a namespaced script import const Script entry(sections[0], fileName, major, minor); _scripts.append(entry); } else { const Component entry(sections[0], fileName, major, minor); _components.insertMulti(entry.typeName, entry); } } else { reportError(lineNumber, 0, QStringLiteral("invalid version %1, expected <major>.<minor>").arg(sections[1])); } } else { reportError(lineNumber, 0, QStringLiteral("a component declaration requires two or three arguments, but %1 were provided").arg(sectionCount)); } firstLine = false; } return hasError(); }
GenRet VarSymbol::codegenVarSymbol(bool lhsInSetReference) { GenInfo* info = gGenInfo; FILE* outfile = info->cfile; GenRet ret; ret.chplType = typeInfo(); if( outfile ) { // dtString immediates don't actually codegen as immediates, we just use // them for param string functionality. if (immediate && ret.chplType != dtString) { ret.isLVPtr = GEN_VAL; if (immediate->const_kind == CONST_KIND_STRING) { ret.c += '"'; ret.c += immediate->v_string; ret.c += '"'; } else if (immediate->const_kind == NUM_KIND_BOOL) { std::string bstring = (immediate->bool_value())?"true":"false"; const char* castString = "("; switch (immediate->num_index) { case BOOL_SIZE_1: case BOOL_SIZE_SYS: case BOOL_SIZE_8: castString = "UINT8("; break; case BOOL_SIZE_16: castString = "UINT16("; break; case BOOL_SIZE_32: castString = "UINT32("; break; case BOOL_SIZE_64: castString = "UINT64("; break; default: INT_FATAL("Unexpected immediate->num_index: %d\n", immediate->num_index); } ret.c = castString + bstring + ")"; } else if (immediate->const_kind == NUM_KIND_INT) { int64_t iconst = immediate->int_value(); if (iconst == (1ll<<63)) { ret.c = "-INT64(9223372036854775807) - INT64(1)"; } else if (iconst <= -2147483648ll || iconst >= 2147483647ll) { ret.c = "INT64(" + int64_to_string(iconst) + ")"; } else { const char* castString = "("; switch (immediate->num_index) { case INT_SIZE_8: castString = "INT8("; break; case INT_SIZE_16: castString = "INT16("; break; case INT_SIZE_32: castString = "INT32("; break; case INT_SIZE_64: castString = "INT64("; break; default: INT_FATAL("Unexpected immediate->num_index: %d\n", immediate->num_index); } ret.c = castString + int64_to_string(iconst) + ")"; } } else if (immediate->const_kind == NUM_KIND_UINT) { uint64_t uconst = immediate->uint_value(); if( uconst <= (uint64_t) INT32_MAX ) { const char* castString = "("; switch (immediate->num_index) { case INT_SIZE_8: castString = "UINT8("; break; case INT_SIZE_16: castString = "UINT16("; break; case INT_SIZE_32: castString = "UINT32("; break; case INT_SIZE_64: castString = "UINT64("; break; default: INT_FATAL("Unexpected immediate->num_index: %d\n", immediate->num_index); } ret.c = castString + uint64_to_string(uconst) + ")"; } else { ret.c = "UINT64(" + uint64_to_string(uconst) + ")"; } } else { ret.c = cname; // in C, all floating point literals are (double) } } else { // not immediate // is it a constant extern? If it is, it might be for example // an enum or #define'd value, in which case taking the address // of it is simply nonsense. Therefore, we code generate // extern const symbols as GEN_VAL (ie not an lvalue). if( hasFlag(FLAG_CONST) && hasFlag(FLAG_EXTERN) ) { ret.isLVPtr = GEN_VAL; ret.c = cname; } else { QualifiedType qt = qualType(); if (lhsInSetReference) { ret.c = '&'; ret.c += cname; ret.isLVPtr = GEN_PTR; if (qt.isRef() && !qt.isRefType()) ret.chplType = getOrMakeRefTypeDuringCodegen(typeInfo()); else if (qt.isWideRef() && !qt.isWideRefType()) { Type* refType = getOrMakeRefTypeDuringCodegen(typeInfo()); ret.chplType = getOrMakeWideTypeDuringCodegen(refType); } } else { if (qt.isRef() && !qt.isRefType()) { ret.c = cname; ret.isLVPtr = GEN_PTR; } else if(qt.isWideRef() && !qt.isWideRefType()) { ret.c = cname; ret.isLVPtr = GEN_WIDE_PTR; } else { ret.c = '&'; ret.c += cname; ret.isLVPtr = GEN_PTR; } } } // Print string contents in a comment if developer mode // and savec is set. if (developer && 0 != strcmp(saveCDir, "") && immediate && ret.chplType == dtString && immediate->const_kind == CONST_KIND_STRING) { if (strstr(immediate->v_string, "/*") || strstr(immediate->v_string, "*/")) { // Don't emit comment b/c string contained comment character. } else { ret.c += " /* \""; ret.c += immediate->v_string; ret.c += "\" */"; } } } return ret; } else { #ifdef HAVE_LLVM // for LLVM // Handle extern type variables. if( hasFlag(FLAG_EXTERN) && isType() ) { // code generate the type. GenRet got = typeInfo(); return got; } // for nil, generate a void pointer of chplType dtNil // to allow LLVM pointer cast // e.g. T = ( (locale) (nil) ); // // We would just compare against dtNil, but in some cases // the code generator needs to assign e.g. // _ret:dtNil = nil if( typeInfo() == dtNil && 0 == strcmp(cname, "nil") ) { GenRet voidPtr; voidPtr.val = llvm::Constant::getNullValue(info->builder->getInt8PtrTy()); voidPtr.chplType = dtNil; return voidPtr; } if (typeInfo() == dtBool){ // since "true" and "false" are read into the LVT during ReadMacrosAction // they will generate an LLVM value of type i32 instead of i8 if (0 == strcmp(cname, "false")){ GenRet boolVal = new_UIntSymbol(0, INT_SIZE_8)->codegen(); return boolVal; } if (0 == strcmp(cname, "true")){ GenRet boolVal = new_UIntSymbol(1, INT_SIZE_8)->codegen(); return boolVal; } } if(!isImmediate()) { // check LVT for value GenRet got = info->lvt->getValue(cname); got.chplType = typeInfo(); if( got.val ) { return got; } } if(isImmediate()) { ret.isLVPtr = GEN_VAL; if(immediate->const_kind == CONST_KIND_STRING) { if(llvm::Value *value = info->module->getNamedGlobal(name)) { ret.val = value; ret.isLVPtr = GEN_PTR; return ret; } llvm::Value *constString = codegenImmediateLLVM(immediate); llvm::GlobalVariable *globalValue = llvm::cast<llvm::GlobalVariable>( info->module->getOrInsertGlobal (name, info->builder->getInt8PtrTy())); globalValue->setConstant(true); globalValue->setInitializer(llvm::cast<llvm::Constant>( info->builder->CreateConstInBoundsGEP2_32( #if HAVE_LLVM_VER >= 37 NULL, #endif constString, 0, 0))); ret.val = globalValue; ret.isLVPtr = GEN_PTR; } else { ret.val = codegenImmediateLLVM(immediate); } return ret; } if(std::string(cname) == "0") { // Chapel compiler should not make these. INT_FATAL(" zero value BOO "); return ret; } else if (std::string(cname) == "NULL") { GenRet voidPtr; voidPtr.val = llvm::Constant::getNullValue(info->builder->getInt8PtrTy()); voidPtr.chplType = typeInfo(); return voidPtr; } #endif } INT_FATAL("Could not code generate %s - " "perhaps it is a complex macro?", cname); return ret; }