Esempio n. 1
0
Cell cellArith(Op o, Cell c1, Cell c2) {
again:
  if (c1.m_type == KindOfInt64) {
    for (;;) {
      if (c2.m_type == KindOfInt64)  return o(c1.m_data.num, c2.m_data.num);
      if (c2.m_type == KindOfDouble) return o(c1.m_data.num, c2.m_data.dbl);
      cellCopy(numericConvHelper(c2), c2);
      assert(c2.m_type == KindOfInt64 || c2.m_type == KindOfDouble);
    }
  }

  if (c1.m_type == KindOfDouble) {
    for (;;) {
      if (c2.m_type == KindOfDouble) return o(c1.m_data.dbl, c2.m_data.dbl);
      if (c2.m_type == KindOfInt64)  return o(c1.m_data.dbl, c2.m_data.num);
      cellCopy(numericConvHelper(c2), c2);
      assert(c2.m_type == KindOfInt64 || c2.m_type == KindOfDouble);
    }
  }

  if (isArrayType(c1.m_type) && isArrayType(c2.m_type)) {
    return make_tv<KindOfArray>(o(c1.m_data.parr, c2.m_data.parr));
  }

  cellCopy(numericConvHelper(c1), c1);
  assert(c1.m_type == KindOfInt64 || c1.m_type == KindOfDouble);
  goto again;
}
Esempio n. 2
0
bool cellGreaterOrEqual(Cell c1, Cell c2) {
  assert(cellIsPlausible(c1));
  assert(cellIsPlausible(c2));

  if ((isArrayType(c1.m_type) && isArrayType(c2.m_type)) ||
      (c1.m_type == KindOfObject && c2.m_type == KindOfObject) ||
      (c1.m_type == KindOfResource && c2.m_type == KindOfResource)) {
    return cellGreater(c1, c2) || cellEqual(c1, c2);
  }
  if ((c1.m_type == KindOfDouble && std::isnan(c1.m_data.dbl)) ||
      (c2.m_type == KindOfDouble && std::isnan(c2.m_data.dbl))) {
    return cellGreater(c1, c2) || cellEqual(c1, c2);
  }
  return !cellLess(c1, c2);
}
Esempio n. 3
0
PyType PyType::lookupType(const std::string &typeNameIn, ULONG64 module)
{
    if (debuggingTypeEnabled())
        DebugPrint() << "lookup type '" << typeNameIn << "'";
    std::string typeName = typeNameIn;
    trimBack(typeName);
    trimFront(typeName);

    if (isPointerType(typeName) || isArrayType(typeName))
        return PyType(0, 0, typeName);

    if (typeName.find("enum ") == 0)
        typeName.erase(0, 5);
    if (endsWith(typeName, " const"))
        typeName.erase(typeName.length() - 6);
    if (typeName == "__int64" || typeName == "unsigned __int64")
        typeName.erase(typeName.find("__"), 2);

    const static std::regex typeNameRE("^[a-zA-Z_][a-zA-Z0-9_]*!?[a-zA-Z0-9_<>:, \\*\\&\\[\\]]*$");
    if (!std::regex_match(typeName, typeNameRE))
        return PyType();

    CIDebugSymbols *symbols = ExtensionCommandContext::instance()->symbols();
    ULONG typeId;
    HRESULT result = S_FALSE;
    if (module != 0 && !isIntegralType(typeName) && !isFloatType(typeName))
        result = symbols->GetTypeId(module, typeName.c_str(), &typeId);
    if (FAILED(result) || result == S_FALSE)
        result = symbols->GetSymbolTypeId(typeName.c_str(), &typeId, &module);
    if (FAILED(result))
        return createUnresolvedType(typeName);
    return PyType(module, typeId, typeName);

}
Esempio n. 4
0
void DataWalker::traverseData(ArrayData* data,
                              DataFeature& features,
                              PointerSet& visited) const {
  for (ArrayIter iter(data); iter; ++iter) {
    const Variant& var = iter.secondRef();

    if (var.isReferenced()) {
      Variant *pvar = var.getRefData();
      if (markVisited(pvar, features, visited)) {
        if (canStopWalk(features)) return;
        continue; // don't recurse forever; we already went down this path
      }
      // Right now consider it circular even if the referenced variant only
      // showed up in one spot.  This could be revisted later.
      features.isCircular = true;
      if (canStopWalk(features)) return;
    }

    auto const type = var.getType();
    // cheap enough, do it always
    features.hasRefCountReference = isRefcountedType(type);
    if (type == KindOfObject) {
      features.hasObjectOrResource = true;
      traverseData(var.getObjectData(), features, visited);
    } else if (isArrayType(type)) {
      traverseData(var.getArrayData(), features, visited);
    } else if (type == KindOfResource) {
      features.hasObjectOrResource = true;
    }
    if (canStopWalk(features)) return;
  }
}
Esempio n. 5
0
	ArrayType::ArrayType(const NodePtr& node) {
		assert_true(node) << "Given node is null!";

		// support expressions as input
		auto type = node.isa<GenericTypePtr>();
		if (auto expr = node.isa<ExpressionPtr>()) type = expr->getType().isa<GenericTypePtr>();

		// check given node type
		assert_true(isArrayType(type)) << "Given node " << *node << " is not a array type!";

		// process node type
		if(isInf(type->getTypeParameter(1))) {
			// unknown sized array
			*this = ArrayType(type->getTypeParameter(0), ExpressionPtr());
		} else if (auto num = type->getTypeParameter(1).isa<NumericTypePtr>()) {
			// variable or fixed sized array
			*this = ArrayType(type->getTypeParameter(0), num->getValue());
		} else {
			// check validity
			auto size = type->getTypeParameter(1).isa<TypeVariablePtr>();
			assert_true(size) << "Invalid size parameter: " << *size << " of kind: " << size->getNodeType();
			// generic array type
			*this = ArrayType(type->getTypeParameter(0), size);
		}
	}
Esempio n. 6
0
File: type.cpp Progetto: StetHD/hhvm
Type typeFromTV(const TypedValue* tv) {
  assertx(tv->m_type == KindOfClass || tvIsPlausible(*tv));

  if (tv->m_type == KindOfObject) {
    auto const cls = tv->m_data.pobj->getVMClass();

    // We only allow specialization on classes that can't be overridden for
    // now.  If this changes, then this will need to specialize on sub object
    // types instead.
    if (!cls || !(cls->attrs() & AttrNoOverride)) return TObj;
    return Type::ExactObj(cls);
  }

  if (isArrayType(tv->m_type)) {
    return Type::Array(tv->m_data.parr->kind());
  }

  auto outer = tv->m_type;
  auto inner = KindOfUninit;

  if (outer == KindOfPersistentString) outer = KindOfString;
  if (outer == KindOfRef) {
    inner = tv->m_data.pref->tv()->m_type;
    if (inner == KindOfPersistentString) inner = KindOfString;
    else if (inner == KindOfPersistentArray) inner = KindOfArray;
  }
  return Type(outer, inner);
}
Esempio n. 7
0
/**
 * Add an instruction to compute the address of a variable.
 *
 * @param instList a Dlist of instructions
 * @param varSymtab a symbol table for the variable
 * @param regSymtab a symbol table for the registers
 * @param varIndex the symbol table index for a variable
 * @return the symbol table index of the result register
 */
int emitComputeVariableAddress(DList instList, SymTable varSymtab, SymTable regSymtab, int varIndex) {
	

	int regIndex = getFreeIntegerRegisterIndex(regSymtab);
	
	int varTypeIndex = (int)SymGetFieldByIndex(varSymtab,varIndex,SYMTAB_TYPE_INDEX_FIELD);
	
	if (!isArrayType(regSymtab,varTypeIndex)) {
		char* regName = (char*)SymGetFieldByIndex(regSymtab,regIndex,SYM_NAME_FIELD);

		int offset = (int)SymGetFieldByIndex(varSymtab,varIndex,SYMTAB_OFFSET_FIELD);
		char offsetStr[10];

		snprintf(offsetStr,9,"%d",offset);

		char *inst;
		if (offset < 0)
			inst = nssave(4,"\tadd ",regName,", $fp, ",offsetStr);
		else
			inst = nssave(4,"\tadd ",regName,", $gp, ",offsetStr);
		dlinkAppend(instList,dlinkNodeAlloc(inst));
	}
	else {
		char msg[80];

		snprintf(msg,80,"Array variable %s used as a scalar",
				(char*)SymGetFieldByIndex(varSymtab,varIndex,SYM_NAME_FIELD));
		SomeLife_error(msg);
	}

	return regIndex;

}
// FIXME: add support for derived types.
// FIXME: check default character kind.
bool Sema::CheckEquivalenceType(QualType ExpectedType, const Expr *E) {
  auto ObjectType = E->getType();
  if(ObjectType->isArrayType())
    ObjectType = ObjectType->asArrayType()->getElementType();

  if(ExpectedType->isCharacterType()) {
    if(!ObjectType->isCharacterType()) {
      Diags.Report(E->getLocation(),
                   diag::err_typecheck_expected_char_expr)
        << ObjectType << E->getSourceRange();
      return true;
    }
  } else if(ExpectedType->isBuiltinType()) {
    if(IsDefaultBuiltinOrDoublePrecisionType(ExpectedType)) {
      if(!IsDefaultBuiltinOrDoublePrecisionType(ObjectType)) {
        Diags.Report(E->getLocation(),
                     diag::err_typecheck_expected_default_kind_expr)
          << ObjectType << E->getSourceRange();
        return true;
      }
    } else {
      if(!AreTypesOfSameKind(ExpectedType, ObjectType)) {
        Diags.Report(E->getLocation(), diag::err_typecheck_expected_expr_of_type)
          << ExpectedType << ObjectType
          << E->getSourceRange();
        return true;
      }
    }
  }
  return false;
}
Esempio n. 9
0
PyType PyType::target() const
{
    const std::string &typeName = name();
    if (isPointerType(typeName) || isArrayType(typeName))
        return lookupType(targetName(), m_module);
    return PyType();
}
Esempio n. 10
0
int FuncEmitter::parseNativeAttributes(Attr& attrs_) const {
  int ret = Native::AttrNone;

  auto it = userAttributes.find(s_native.get());
  assertx(it != userAttributes.end());
  const TypedValue userAttr = it->second;
  assertx(isArrayType(userAttr.m_type));
  for (ArrayIter it(userAttr.m_data.parr); it; ++it) {
    Variant userAttrVal = it.second();
    if (userAttrVal.isString()) {
      String userAttrStrVal = userAttrVal.toString();
      if (userAttrStrVal.get()->isame(s_actrec.get())) {
        ret |= Native::AttrActRec;
        attrs_ |= AttrMayUseVV;
      } else if (userAttrStrVal.get()->isame(s_nofcallbuiltin.get())) {
        attrs_ |= AttrNoFCallBuiltin;
      } else if (userAttrStrVal.get()->isame(s_variadicbyref.get())) {
        attrs_ |= AttrVariadicByRef;
      } else if (userAttrStrVal.get()->isame(s_noinjection.get())) {
        attrs_ |= AttrNoInjection;
      } else if (userAttrStrVal.get()->isame(s_numargs.get())) {
        ret |= Native::AttrTakesNumArgs;
      } else if (userAttrStrVal.get()->isame(s_opcodeimpl.get())) {
        ret |= Native::AttrOpCodeImpl;
      } else if (userAttrStrVal.get()->isame(s_readsCallerFrame.get())) {
        attrs_ |= AttrReadsCallerFrame;
      } else if (userAttrStrVal.get()->isame(s_writesCallerFrame.get())) {
        attrs_ |= AttrWritesCallerFrame;
      }
    }
  }
  return ret;
}
Esempio n. 11
0
void CodeGenFunction::EmitVarDecl(const VarDecl *D) {
  if(D->isParameter() ||
     D->isArgument()  ||
     D->isFunctionResult()) return;

  if(D->hasStorageSet()) {
    if(auto E = dyn_cast<EquivalenceSet>(D->getStorageSet())) {
      auto Set = EmitEquivalenceSet(E);
      auto Ptr = EmitEquivalenceSetObject(Set, D);
      LocalVariables.insert(std::make_pair(D, Ptr));
    } else if(auto CB = dyn_cast<CommonBlockSet>(D->getStorageSet()))
      EmitCommonBlock(CB);
    else
      llvm_unreachable("invalid storage set");
    return;
  }

  llvm::Value *Ptr;
  auto Type = D->getType();
  if(Type.hasAttributeSpec(Qualifiers::AS_save) && !IsMainProgram) {
    Ptr = CGM.EmitGlobalVariable(CurFn->getName(), D);
    HasSavedVariables = true;
  } else {
    if(Type->isArrayType())
      Ptr = CreateArrayAlloca(Type, D->getName());
    else Ptr = Builder.CreateAlloca(ConvertTypeForMem(Type),
                                    nullptr, D->getName());
  }
  LocalVariables.insert(std::make_pair(D, Ptr));
}
Esempio n. 12
0
//--------------------------------------------------------------
bool ofxMuiNumberData::isValidIndex(int index) const {
    if(index == 0 || (index > 0 && index < getNumValues() && isArrayType())) {
        return true;
    } else {
        ofLog(OF_LOG_ERROR, "ofxMuiNumberData: invalid index " + index);
        return false; // a negative index is never good
    } 
}
Esempio n. 13
0
//--------------------------------------------------------------
bool ofxMuiNumberData::isValidInsertionIndex(int index) const {
    if(isArrayType() && index > -1 && index <= getNumValues()) {
        return true;
    } else {
        ofLog(OF_LOG_ERROR, "ofxMuiNumberData: invalid insertion index " + ofToString(index) + " where size = " +ofToString(getNumValues()));
        return false;
    }
}
Esempio n. 14
0
bool cellLessOrEqual(Cell c1, Cell c2) {
  assert(cellIsPlausible(c1));
  assert(cellIsPlausible(c2));

  if ((isArrayType(c1.m_type) && isArrayType(c2.m_type)) ||
      (c1.m_type == KindOfObject && c2.m_type == KindOfObject) ||
      (c1.m_type == KindOfResource && c2.m_type == KindOfResource)) {
    return cellLess(c1, c2) || cellEqual(c1, c2);
  }

  // We have to treat NaN specially: NAN <= NAN is false, for example, so we
  // can't just say !(NAN > NAN).
  if ((c1.m_type == KindOfDouble && std::isnan(c1.m_data.dbl)) ||
      (c2.m_type == KindOfDouble && std::isnan(c2.m_data.dbl))) {
    return cellLess(c1, c2) || cellEqual(c1, c2);
  }
  return !cellGreater(c1, c2);
}
Esempio n. 15
0
//--------------------------------------------------------------
bool ofxMuiNumberData::canUseSetAll() const {
    if(getNumValues() > 0 && isArrayType()) {
        return true;
    } else {
        ofLog(OF_LOG_WARNING, "ofxMuiNumberData: unable to set all - invalid numValues < 1 or not array type");
        return false; // a negative index is never good
    }
                                
}
Esempio n. 16
0
Cell cellArithO(Op o, Check ck, Over ov, Cell c1, Cell c2) {
  if (isArrayType(c1.m_type) && isArrayType(c2.m_type)) {
    return cellArith(o, c1, c2);
  }

  auto ensure_num = [](Cell& c) {
    if (c.m_type != KindOfInt64 && c.m_type != KindOfDouble) {
      cellCopy(numericConvHelper(c), c);
    }
  };

  ensure_num(c1);
  ensure_num(c2);
  auto both_ints = (c1.m_type == KindOfInt64 && c2.m_type == KindOfInt64);
  int64_t a = c1.m_data.num;
  int64_t b = c2.m_data.num;

  return (both_ints && ck(a,b)) ? ov(a,b) : cellArith(o, c1, c2);
}
Esempio n. 17
0
/*
 * Constructs a scalar array with all the shape field names, this/self/parent,
 * classes, type accesses, and type aliases resolved.
 */
Array TypeStructure::resolve(const Class::Const& typeCns,
                             const Class* typeCnsCls,
                             bool& persistent) {
  assert(typeCns.isType());
  assert(isArrayType(typeCns.val.m_type));
  assert(typeCns.name);
  assert(typeCnsCls);

  Array arr(typeCns.val.m_data.parr);
  return resolveTS(arr, typeCns, typeCnsCls, Array(), persistent);
}
Esempio n. 18
0
/// ParseDesignator - Parse a designator. Return null if current token is not a
/// designator.
///
///   [R601]:
///     designator :=
///         object-name
///      or array-element
///      or array-section
///      or coindexed-named-object
///      or complex-part-designator
///      or structure-component
///      or substring
///
/// FIXME: substring for a character array
ExprResult Parser::ParseDesignator(bool IsLvalue) {
  auto E = ParseNameOrCall();

  struct ScopedFlag {
    bool value;
    bool &dest;

    ScopedFlag(bool &flag) : dest(flag) {
      value = flag;
    }
    ~ScopedFlag() {
      dest = value;
    }
  };

  ScopedFlag Flag(DontResolveIdentifiers);
  if(DontResolveIdentifiersInSubExpressions)
    DontResolveIdentifiers = true;

  while(true) {
    if(!E.isUsable())
      break;
    if(IsPresent(tok::l_paren)) {
      auto EType = E.get()->getType();
      if(EType->isArrayType())
        E = ParseArraySubscript(E);
      else if(EType->isCharacterType())
        E = ParseSubstring(E);
      else {
        Diag.Report(Tok.getLocation(), diag::err_unexpected_lparen);
        return ExprError();
      }
    } else if(IsPresent(tok::percent)) {
      auto EType = E.get()->getType();
      if(EType->isRecordType())
        E = ParseStructureComponent(E);
      else {
        Diag.Report(Tok.getLocation(), diag::err_unexpected_percent);
        return ExprError();
      }
    } else if(IsPresent(tok::period)) {
      auto EType = E.get()->getType();
      if(EType->isRecordType())
        E = ParseStructureComponent(E);
      else {
        Diag.Report(Tok.getLocation(), diag::err_unexpected_period);
        return ExprError();
      }
    }
    else break;
  }

  return E;
}
Esempio n. 19
0
void find_var_recursive(const TypedValue* tv,
                        const req::ptr<WddxPacket>& wddxPacket) {
  if (tvIsString(tv)) {
    String var_name{tvCastToString(tv)};
    wddxPacket->add_var(var_name, true);
  }
  if (isArrayType(tv->m_type)) {
    for (ArrayIter iter(tv->m_data.parr); iter; ++iter) {
      find_var_recursive(iter.secondRef().asTypedValue(), wddxPacket);
    }
  }
}
Esempio n. 20
0
llvm::Constant *CodeGenFunction::EmitConstantExpr(const Expr *E) {
  auto T = E->getType();
  if(T->isComplexType())
    return CreateComplexConstant(EmitComplexExpr(E));
  else if(T->isCharacterType()) //FIXME
    ;//;return CreateCharacterConstant(EmitCharacterExpr(E));
  else if(T->isLogicalType())
    return cast<llvm::Constant>(EmitLogicalValueExpr(E));
  else if(T->isArrayType())
    return EmitConstantArrayExpr(dyn_cast<ArrayConstructorExpr>(E));
  else
    return cast<llvm::Constant>(EmitScalarExpr(E));
}
Esempio n. 21
0
TCResult ast::SliceOp::typecheck(sst::TypecheckState* fs, fir::Type* inferred)
{
	fs->pushLoc(this);
	defer(fs->popLoc());

	fs->pushAnonymousTree();
	defer(fs->popTree());

	auto array = this->expr->typecheck(fs).expr();
	auto ty = array->type;

	fs->enterSubscript(array);
	defer(fs->leaveSubscript());

	fir::Type* elm = 0;
	if(ty->isDynamicArrayType() || ty->isArraySliceType() || ty->isArrayType())
		elm = ty->getArrayElementType();

	else if(ty->isStringType())
		elm = fir::Type::getInt8();

	else if(ty->isPointerType())
		elm = ty->getPointerElementType();

	else
		error(array, "invalid type '%s' for slice operation", ty);

	auto begin = this->start ? this->start->typecheck(fs, fir::Type::getInt64()).expr() : 0;
	auto end = this->end ? this->end->typecheck(fs, fir::Type::getInt64()).expr() : 0;

	if(begin && !begin->type->isIntegerType())
		error(begin, "expected integer type for start index of slice; found '%s'", begin->type);

	if(end && !end->type->isIntegerType())
		error(end, "expected integer type for end index of slice; found '%s'", end->type);

	//* how it goes:
	// 1. strings and dynamic arrays are always sliced mutably.
	// 2. slices of slices naturally inherit their mutability.
	// 3. arrays are sliced immutably.
	// 4. pointers inherit their mutability as well.

	bool ismut = sst::getMutabilityOfSliceOfType(ty);

	auto ret = util::pool<sst::SliceOp>(this->loc, fir::ArraySliceType::get(elm, ismut));
	ret->expr = array;
	ret->begin = begin;
	ret->end = end;

	return TCResult(ret);
}
Esempio n. 22
0
/**
 * Compute the address of an array element and store it in a register.
 *
 * @param instList a list of instructions
 * @param varSymtab a symbol table for the variable
 * @param regSymtab a symbol table for the registers
 * @param varIndex the symbol table index of the array variable
 * @param subIndex the symbol table index of the register holding the subscript value
 * @return the symbol table index of the register holding the address of the
 * 		   array element.
 */
int emitComputeArrayAddress(DList instList, SymTable varSymtab, int varIndex, SymTable regSymtab, int subIndex) {
	
	int regIndex = getFreeIntegerRegisterIndex(regSymtab);
	int varTypeIndex = (int)SymGetFieldByIndex(varSymtab,varIndex,SYMTAB_TYPE_INDEX_FIELD);
	
	if (isArrayType(regSymtab,varTypeIndex)) {
		char* regName = (char*)SymGetFieldByIndex(regSymtab,regIndex,SYM_NAME_FIELD);
	
		int offset = (int)SymGetFieldByIndex(varSymtab,varIndex,SYMTAB_OFFSET_FIELD);
	
		char offsetStr[10];
	
		snprintf(offsetStr,9,"%d",offset);
	
		/* compute base address of array */
		char *inst;

		inst = nssave(4,"\tadd ",regName,", $gp, ",offsetStr);
		dlinkAppend(instList,dlinkNodeAlloc(inst));

		/* compute offset base on subscript */
		char* subRegName = (char*)SymGetFieldByIndex(regSymtab,subIndex,SYM_NAME_FIELD);
		int arrayBase = getArrayBase(regSymtab, varTypeIndex);
		
		snprintf(offsetStr,9,"%d",arrayBase);
		inst = nssave(6,"\tsub ", subRegName, ", ", subRegName, ", ", offsetStr);
		dlinkAppend(instList,dlinkNodeAlloc(inst));

		inst = nssave(5,"\tsll ", subRegName, ", ", subRegName, ", 2");
		dlinkAppend(instList,dlinkNodeAlloc(inst));

		/* compute element address */
		inst = nssave(6,"\tadd ", regName, ", ", regName, ", ", subRegName);
		dlinkAppend(instList,dlinkNodeAlloc(inst));
	}
	else {
		char msg[80];

		snprintf(msg,80,"Scalar variable %s used as an array",
				(char*)SymGetFieldByIndex(varSymtab,varIndex,SYM_NAME_FIELD));
		SomeLife_error(msg);
	}
	
	freeIntegerRegister((int)SymGetFieldByIndex(regSymtab,subIndex,SYMTAB_REGISTER_INDEX_FIELD));

	return regIndex;

}
Esempio n. 23
0
std::string PyType::targetName() const
{
    const std::string &typeName = name();
    if (isPointerType(typeName))
        return stripPointerType(typeName);
    if (isArrayType(typeName)) {
        const auto openArrayPos = typeName.find_first_of('[');
        if (openArrayPos == std::string::npos)
            return typeName;
        const auto closeArrayPos = typeName.find_first_of(']', openArrayPos);
        if (closeArrayPos == std::string::npos)
            return typeName;
        return typeName.substr(0, openArrayPos) + typeName.substr(closeArrayPos + 1);
    }
    return typeName;
}
Esempio n. 24
0
int PyType::code() const
{
    if (!m_resolved)
        return TypeCodeUnresolvable;

    if (m_tag < 0) {
        // try to parse typeName
        const std::string &typeName = name();
        if (typeName.empty())
            return TypeCodeUnresolvable;
        if (isPointerType(typeName))
            return TypeCodePointer;
        if (isArrayType(typeName))
            return TypeCodeArray;
        if (typeName.find("<function>") == 0)
            return TypeCodeFunction;
        if (isIntegralType(typeName))
            return TypeCodeIntegral;
        if (isFloatType(typeName))
            return TypeCodeFloat;

        IDebugSymbolGroup2 *sg = 0;
        if (FAILED(ExtensionCommandContext::instance()->symbols()->CreateSymbolGroup2(&sg)))
            return TypeCodeStruct;

        if (knownType(name(), 0) != KT_Unknown)
            return TypeCodeStruct;

        const std::string helperValueName = SymbolGroupValue::pointedToSymbolName(0, name(true));
        ULONG index = DEBUG_ANY_ID;
        if (SUCCEEDED(sg->AddSymbol(helperValueName.c_str(), &index)))
            m_tag = PyValue(index, sg).tag();
        sg->Release();
    }
    switch (m_tag) {
    case SymTagUDT: return TypeCodeStruct;
    case SymTagEnum: return TypeCodeEnum;
    case SymTagTypedef: return TypeCodeTypedef;
    case SymTagFunctionType: return TypeCodeFunction;
    case SymTagPointerType: return TypeCodePointer;
    case SymTagArrayType: return TypeCodeArray;
    case SymTagBaseType: return isIntegralType(name()) ? TypeCodeIntegral : TypeCodeFloat;
    default: break;
    }

    return TypeCodeStruct;
}
Esempio n. 25
0
void CodeGenFunction::EmitVarInitializer(const VarDecl *D) {
  assert(D->hasInit());

  auto T = D->getType();
  if(T->isArrayType()) {
    auto Dest = Builder.CreateConstInBoundsGEP2_32(ConvertTypeForMem(T),
                                                   GetVarPtr(D), 0, 0);
    auto Init = cast<ArrayConstructorExpr>(D->getInit())->getItems();
    for(size_t I = 0; I < Init.size(); ++I) {
      auto Val = EmitRValue(Init[I]);
      EmitStoreCharSameLength(Val, Builder.CreateConstInBoundsGEP1_64(Dest, I), T.getSelfOrArrayElementType());
    }
    return;
  }
  auto Val = EmitRValue(D->getInit());
  EmitStoreCharSameLength(Val, GetVarPtr(D), D->getType());
}
Esempio n. 26
0
bool cellSame(Cell c1, Cell c2) {
  assert(cellIsPlausible(c1));
  assert(cellIsPlausible(c2));

  bool const null1 = isNullType(c1.m_type);
  bool const null2 = isNullType(c2.m_type);
  if (null1 && null2) return true;
  if (null1 || null2) return false;

  switch (c1.m_type) {
    case KindOfBoolean:
    case KindOfInt64:
      if (c2.m_type != c1.m_type) return false;
      return c1.m_data.num == c2.m_data.num;

    case KindOfDouble:
      if (c2.m_type != c1.m_type) return false;
      return c1.m_data.dbl == c2.m_data.dbl;

    case KindOfPersistentString:
    case KindOfString:
      if (!isStringType(c2.m_type)) return false;
      return c1.m_data.pstr->same(c2.m_data.pstr);

    case KindOfPersistentArray:
    case KindOfArray:
      if (!isArrayType(c2.m_type)) return false;
      return c1.m_data.parr->equal(c2.m_data.parr, true);

    case KindOfObject:
      return c2.m_type == KindOfObject &&
        c1.m_data.pobj == c2.m_data.pobj;

    case KindOfResource:
      return c2.m_type == KindOfResource &&
        c1.m_data.pres == c2.m_data.pres;

    case KindOfUninit:
    case KindOfNull:
    case KindOfRef:
    case KindOfClass:
      break;
  }
  not_reached();
}
Esempio n. 27
0
void logSerDes(const char* format, const char* op,
               const String& serialized, const Variant& value) {
  StructuredLogEntry sample;
  sample.setStr("format", format);
  sample.setStr("operation", op);
  DataType t = value.getType();
  sample.setStr("type", tname(t));
  if (isArrayType(t)) {
    sample.setInt("array_len", value.toCArrRef().length());
  }
  if (auto sd = serialized.get()) {
    sample.setInt("length_ser", sd->size());
    sample.setInt("hash_ser", sd->hash());
  }
  StackTrace st;
  sample.setStackTrace("stack", st);
  StructuredLog::log("hhvm_serdes", sample);
}
Esempio n. 28
0
void zBoxAndProxy(TypedValue* arg) {
  if (arg->m_type != KindOfRef) {
    tvBox(arg);
  }
  auto inner = arg->m_data.pref->tv();
  assert(!isHackArrayType(inner->m_type));
  if (isArrayType(inner->m_type) && !inner->m_data.parr->isProxyArray()) {
    ArrayData * inner_arr = inner->m_data.parr;
    if (inner_arr->cowCheck()) {
      ArrayData * tmp = inner_arr->copy();
      if (inner_arr != tmp) {
        inner_arr->decRefAndRelease();
        inner_arr = tmp;
      }
    }
    inner->m_data.parr = ProxyArray::Make(inner_arr);
    inner->m_type = KindOfArray;
  }
}
Esempio n. 29
0
PyFields PyType::fields() const
{
    CIDebugSymbols *symbols = ExtensionCommandContext::instance()->symbols();
    PyFields fields;
    if (isArrayType(name()) || isPointerType(name()))
        return fields;
    for (ULONG fieldIndex = 0;; ++fieldIndex) {
        ULONG size = 0;
        symbols->GetFieldName(m_module, m_typeId, fieldIndex, NULL, 0, &size);
        if (size == 0)
            break;
        std::string name(size - 1, '\0');
        if (FAILED(symbols->GetFieldName(m_module, m_typeId, fieldIndex, &name[0], size, NULL)))
            break;

        fields.push_back(PyField(name, *this));
    }
    return fields;
}
Esempio n. 30
0
//--------------------------------------------------------------
void ofxMuiNumberData::init(int initialSize) {
    
    if(!isArrayType() && initialSize > 1) {
        ofLog(OF_LOG_ERROR, "ofxMuiNumberData: trying to init an array, but data type is incorrect");
    }
    
    _defaults = &ofxMuiDefaults::getInstance(); // get a link to the singleton

    // no range to start
    hasRange = false;
    // do not use global to start.  if you do, this will fail

    for(int i = 0; i < initialSize; i++) {
        addValue(0);
    }
    
    //cout << "after setup, initial size is " << getNumValues() << endl;

    //cout << ">>INIT BOUNDS >> " << getBounds().toString() << endl;
    //cout << ">>INIT RANGE >> " << getRange().toString() << endl;
    //cout << ">>>>>>>>>>" << endl;
    
}