local void InitCharArray( TYPEPTR typ ) { unsigned len; STRING_LITERAL *str_lit; unsigned long size; DATA_QUAD dq; /* This function handles the initialization of statements like: */ /* char name[4] = "abcd"; */ str_lit = GetLiteral(); if( CompFlags.wide_char_string ) CErr1( ERR_TYPE_MISMATCH ); len = str_lit->length; if( typ->u.array->unspecified_dim ) typ->u.array->dimension = len; size = typ->u.array->dimension; if( len > size ) { if( (len - size) > 1 ) { CWarn1( WARN_LIT_TOO_LONG, ERR_LIT_TOO_LONG ); } str_lit->length = len = size; /* chop the string */ } dq.type = QDT_CONST; dq.flags = Q_DATA; dq.u.string_leaf = str_lit; GenDataQuad( &dq, len ); if( size > len ) { /* if array > len of literal */ ZeroBytes( size - len ); } CompFlags.non_zero_data = 1; }
void SimplifyExpression(TExpressionPtr& expr) { assert(expr.get() != nullptr); const auto value = SimplifyExpressionImpl(expr); // SimplifyExpressionImpl simplifies only child expressions of each operation // expression, so the root can be still not simplifed. Let's correct this if so. if (LiteralType::None != value && LiteralType::None == GetLiteral(expr)) { expr = std::make_unique<LiteralExpression>(value); } }
local void InitWCharArray( TYPEPTR typ ) { unsigned len; unsigned i; STRING_LITERAL *str_lit; unsigned value; unsigned short *pwc; unsigned long size; DATA_QUAD dq; dq.type = QDT_SHORT; dq.flags = Q_DATA; /* This function handles the initialization of statements like: */ /* wchar_t name[5] = L"abcd"; */ str_lit = GetLiteral(); if( !CompFlags.wide_char_string ) CErr1( ERR_TYPE_MISMATCH ); len = str_lit->length / sizeof(unsigned short); if( typ->u.array->unspecified_dim ) { typ->u.array->dimension = len; } size = typ->u.array->dimension; if( len > size ) { if( (len - size) > 1 ) { CWarn1( WARN_LIT_TOO_LONG, ERR_LIT_TOO_LONG ); } len = size; } pwc = (unsigned short *)str_lit->literal; i = 0; while( i < len ) { value = *pwc++; if( value != 0 ) CompFlags.non_zero_data = 1; dq.u.long_values[0] = value; GenDataQuad( &dq, sizeof( target_short ) ); ++i; } if( i < size ) { ZeroBytes( (size - i) * sizeof(unsigned short) ); } FreeLiteral( str_lit ); }