MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / sv_trySimulate_At

Method sv_trySimulate_At

src/ast/ast_simulate.cpp:1879–1994  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1877 }
1878
1879 SimNode * SimulateVisitor::sv_trySimulate_At(const ExprAt * expr, uint32_t extraOffset, const TypeDeclPtr & r2vType) {
1880 const auto &at = expr->at;
1881 if ( expr->subexpr->type->isVectorType() ) {
1882 return nullptr;
1883 } else if ( expr->subexpr->type->isGoodTableType() ) {
1884 return nullptr;
1885 } else if ( expr->subexpr->type->isHandle() ) {
1886 SimNode * result;
1887 if ( r2vType->baseType!=Type::none ) {
1888 result = expr->subexpr->type->annotation->simulateGetAtR2V(context, at, r2vType, expr->subexpr, expr->index, extraOffset);
1889 if ( !result ) {
1890 context.thisProgram->error("integration error, simulateGetAtR2V returned null", "", "",
1891 at, CompilationError::internal_expression );
1892 }
1893 } else {
1894 result = expr->subexpr->type->annotation->simulateGetAt(context, at, r2vType, expr->subexpr, expr->index, extraOffset);
1895 if ( !result ) {
1896 context.thisProgram->error("integration error, simulateGetAt returned null", "", "",
1897 at, CompilationError::internal_expression );
1898 }
1899 }
1900 return result;
1901 } else if ( expr->subexpr->type->isGoodArrayType() ) {
1902 auto prv = simulateExpression(expr->subexpr);
1903 auto pidx = simulateExpression(expr->index);
1904 uint32_t stride = expr->subexpr->type->firstType->getSizeOf();
1905 if ( r2vType->baseType!=Type::none ) {
1906 switch ( expr->index->type->baseType ) {
1907 case Type::tInt64: return context.code->makeValueNode<SimNode_ArrayAtR2V_I64>(r2vType->getR2VType(), at, prv, pidx, stride, extraOffset);
1908 case Type::tUInt64: return context.code->makeValueNode<SimNode_ArrayAtR2V_U64>(r2vType->getR2VType(), at, prv, pidx, stride, extraOffset);
1909 default: return context.code->makeValueNode<SimNode_ArrayAtR2V>(r2vType->getR2VType(), at, prv, pidx, stride, extraOffset);
1910 }
1911 } else {
1912 switch ( expr->index->type->baseType ) {
1913 case Type::tInt64: return context.code->makeNode<SimNode_ArrayAt_I64>(at, prv, pidx, stride, extraOffset);
1914 case Type::tUInt64: return context.code->makeNode<SimNode_ArrayAt_U64>(at, prv, pidx, stride, extraOffset);
1915 default: return context.code->makeNode<SimNode_ArrayAt>(at, prv, pidx, stride, extraOffset);
1916 }
1917 }
1918 } else if ( expr->subexpr->type->isPointer() ) {
1919 uint32_t stride = expr->subexpr->type->firstType->getSizeOf();
1920 auto prv = simulateExpression(expr->subexpr);
1921 auto pidx = simulateExpression(expr->index);
1922 if ( r2vType->baseType!=Type::none ) {
1923 switch ( expr->index->type->baseType ) {
1924 case Type::tInt: return context.code->makeValueNode<SimNode_PtrAtR2V_Int>(r2vType->getR2VType(), at, prv, pidx, stride, extraOffset);
1925 case Type::tUInt: return context.code->makeValueNode<SimNode_PtrAtR2V_UInt>(r2vType->getR2VType(), at, prv, pidx, stride, extraOffset);
1926 case Type::tInt64: return context.code->makeValueNode<SimNode_PtrAtR2V_Int64>(r2vType->getR2VType(), at, prv, pidx, stride, extraOffset);
1927 case Type::tUInt64: return context.code->makeValueNode<SimNode_PtrAtR2V_UInt64>(r2vType->getR2VType(), at, prv, pidx, stride, extraOffset);
1928 default:
1929 context.thisProgram->error("internal compilation error, generating ptr at for unsupported index type " + expr->index->type->describe(), "", "", at, CompilationError::internal_expression);
1930 return nullptr;
1931 };
1932 } else {
1933 switch ( expr->index->type->baseType ) {
1934 case Type::tInt: return context.code->makeNode<SimNode_PtrAt<int32_t>>(at, prv, pidx, stride, extraOffset);
1935 case Type::tUInt: return context.code->makeNode<SimNode_PtrAt<uint32_t>>(at, prv, pidx, stride, extraOffset);
1936 case Type::tInt64: return context.code->makeNode<SimNode_PtrAt<int64_t>>(at, prv, pidx, stride, extraOffset);

Callers

nothing calls this directly

Calls 15

simulateExpressionFunction · 0.85
toFunction · 0.85
to_stringFunction · 0.85
isVectorTypeMethod · 0.80
isGoodTableTypeMethod · 0.80
isHandleMethod · 0.80
isGoodArrayTypeMethod · 0.80
getR2VTypeMethod · 0.80
isPointerMethod · 0.80
getStrideMethod · 0.80
simulateGetAtR2VMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected