@@ -941,32 +941,61 @@ private AbstractType CompileBinaryExpression(Context context, Assembler assemble
941941
942942                            case  StringType : 
943943                            { 
944+                                 Assembler  beforeLeftAssembler  =  new ( ) ; 
944945                                Assembler  beforeRightAssembler  =  new ( ) ; 
945946                                Variable  rightCastTempVar  =  null ; 
946-                                 if  ( rightType  is  PointerType  rptr ) 
947-                                 { 
948-                                     if  ( ! PrimitiveType . IsPrimitiveChar ( rptr . Type ) ) 
949-                                         throw  new  CompilerException ( rightOperand . Interval ,  $ "Concatenação de strings não pode ser feita com um ponteiro do tipo '{ rptr . Type } '.") ; 
950947
951-                                      CompileCast ( context ,  rightAssembler ,   beforeRightAssembler ,   rightType ,   leftType ,  false ,  rightOperand . Interval ,  out  rightCastTempVar ) ; 
952-                                  } 
953-                                 else   if   ( rightType   is  not  StringType ) 
948+                                 CompileCast ( context ,  leftAssembler ,   beforeLeftAssembler ,   leftType ,   StringType . STRING ,  false ,  leftOperand . Interval ,  out  var   leftCastTempVar ) ; 
949+ 
950+                                 switch   ( rightType ) 
954951                                { 
955-                                     throw  new  CompilerException ( rightOperand . Interval ,  $ "Concatenação de strings não pode ser feita com o tipo '{ rightType } '.") ; 
952+                                     case  PrimitiveType  rp :  // Concatenação de uma string com um tipo primitivo, isso exige a conversão do primitivo para string para então realizar a concatenação 
953+                                     { 
954+                                         var  rightTempVar  =  context . AcquireTemporaryVariable ( StringType . STRING ,  rightOperand . Interval ) ; 
955+                                         beforeRightAssembler . EmitLoadLocalHostAddress ( rightTempVar . Offset ) ; 
956+ 
957+                                         var  func  =  rp . Primitive  switch 
958+                                         { 
959+                                             Primitive . BOOL  =>  unitySystem . FindFunction ( "BoolParaTexto" ) , 
960+                                             Primitive . CHAR  =>  unitySystem . FindFunction ( "CharParaTexto" ) , 
961+                                             Primitive . BYTE  or Primitive . SHORT  or Primitive . INT  =>  unitySystem . FindFunction ( "IntParaTexto" ) , 
962+                                             Primitive . LONG  =>  unitySystem . FindFunction ( "LongParaTexto" ) , 
963+                                             Primitive . FLOAT  =>  unitySystem . FindFunction ( "FloatParaTexto" ) , 
964+                                             Primitive . DOUBLE  =>  unitySystem . FindFunction ( "DoubleParaTexto" ) , 
965+                                             _ =>  throw  new  CompilerException ( rightOperand . Interval ,  "Operando inválido." ) , 
966+                                         } ; 
967+                                         int  index  =  GetOrAddExternalFunction ( func . Name ,  func . ParameterSize ) ; 
968+                                         rightAssembler . EmitExternCall ( index ) ; 
969+                                         rightAssembler . EmitLoadLocalPtr ( rightTempVar . Offset ) ; 
970+                                         break ; 
971+                                     } 
972+ 
973+                                     case  PointerType  rptr : 
974+                                     { 
975+                                         if  ( ! PrimitiveType . IsPrimitiveChar ( rptr . Type ) ) 
976+                                             throw  new  CompilerException ( rightOperand . Interval ,  $ "Concatenação de strings não pode ser feita com um ponteiro do tipo '{ rptr . Type } '.") ; 
977+ 
978+                                         CompileCast ( context ,  rightAssembler ,  beforeRightAssembler ,  rightType ,  leftType ,  false ,  rightOperand . Interval ,  out  rightCastTempVar ) ; 
979+                                         break ; 
980+                                     } 
981+ 
982+                                     default : 
983+                                         throw  new  CompilerException ( rightOperand . Interval ,  $ "Concatenação de strings não pode ser feita com o tipo '{ rightType } '.") ; 
956984                                } 
957985
958986                                tempVar  =  context . AcquireTemporaryVariable ( StringType . STRING ,  expression . Interval ) ; 
959987                                assembler . EmitLoadLocalHostAddress ( tempVar . Offset ) ; 
960988
989+                                 assembler . Emit ( beforeLeftAssembler ) ; 
961990                                assembler . Emit ( leftAssembler ) ; 
962991                                assembler . Emit ( beforeRightAssembler ) ; 
963992                                assembler . Emit ( rightAssembler ) ; 
964993
965994                                rightCastTempVar ? . Release ( ) ; 
966995
967-                                 var  func  =  unitySystem . FindFunction ( "ConcatenaTextos2" ) ; 
968-                                 int  index  =  GetOrAddExternalFunction ( func . Name ,  func . ParameterSize ) ; 
969-                                 assembler . EmitExternCall ( index ) ; 
996+                                 var  concat  =  unitySystem . FindFunction ( "ConcatenaTextos2" ) ; 
997+                                 int  concatIndex  =  GetOrAddExternalFunction ( concat . Name ,  concat . ParameterSize ) ; 
998+                                 assembler . EmitExternCall ( concatIndex ) ; 
970999
9711000                                assembler . EmitLoadLocalPtr ( tempVar . Offset ) ; 
9721001
0 commit comments