|
@@ -153,10 +153,6 @@ Class IdentExpr Extends Expr
|
|
|
Self.ident=ident
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- Return ident
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
Local value:=scope.FindValue( ident )
|
|
@@ -173,6 +169,11 @@ Class IdentExpr Extends Expr
|
|
|
Return type
|
|
|
End
|
|
|
|
|
|
+ Method ToString:String() Override
|
|
|
+
|
|
|
+ Return ident
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
Class MemberExpr Extends Expr
|
|
@@ -186,10 +187,6 @@ Class MemberExpr Extends Expr
|
|
|
Self.ident=ident
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- Return expr.ToString()+"."+ident
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
Local value:=expr.SemantRValue( scope )
|
|
@@ -212,6 +209,11 @@ Class MemberExpr Extends Expr
|
|
|
Return type2
|
|
|
End
|
|
|
|
|
|
+ Method ToString:String() Override
|
|
|
+
|
|
|
+ Return expr.ToString()+"."+ident
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
Class InvokeExpr Extends Expr
|
|
@@ -225,10 +227,6 @@ Class InvokeExpr Extends Expr
|
|
|
Self.args=args
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- Return expr.ToString()+"("+Join( args )+")"
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
Local args:=SemantArgs( Self.args,scope )
|
|
@@ -239,70 +237,76 @@ Class InvokeExpr Extends Expr
|
|
|
|
|
|
Return ivalue
|
|
|
End
|
|
|
+
|
|
|
+ Method ToString:String() Override
|
|
|
|
|
|
+ Return expr.ToString()+"("+Join( args )+")"
|
|
|
+ End
|
|
|
End
|
|
|
|
|
|
Class GenericExpr Extends Expr
|
|
|
|
|
|
Field expr:Expr
|
|
|
- Field types:TypeExpr[]
|
|
|
+ Field args:Expr[]
|
|
|
|
|
|
- Method New( expr:Expr,types:TypeExpr[],srcpos:Int,endpos:Int )
|
|
|
+ Method New( expr:Expr,args:Expr[],srcpos:Int,endpos:Int )
|
|
|
Super.New( srcpos,endpos )
|
|
|
Self.expr=expr
|
|
|
- Self.types=types
|
|
|
- End
|
|
|
-
|
|
|
- Method ToString:String() Override
|
|
|
- Return expr.ToString()+"<"+Join( types )+">"
|
|
|
+ Self.args=args
|
|
|
End
|
|
|
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
- Local types:=SemantTypes( Self.types,scope )
|
|
|
-
|
|
|
Local value:=expr.Semant( scope )
|
|
|
|
|
|
+ Local args:=New Type[Self.args.Length]
|
|
|
+
|
|
|
+ For Local i:=0 Until args.Length
|
|
|
+ args[i]=Self.args[i].SemantType( scope )
|
|
|
+ Next
|
|
|
+
|
|
|
'FIXME: need proper 'WhereExpr's!
|
|
|
'
|
|
|
Local tvalue:=Cast<TypeValue>( value )
|
|
|
- If tvalue Return New TypeValue( tvalue.ttype.GenInstance( types ) )
|
|
|
+ If tvalue Return New TypeValue( tvalue.ttype.GenInstance( args ) )
|
|
|
|
|
|
- Return value.GenInstance( types )
|
|
|
+ Return value.GenInstance( args )
|
|
|
End
|
|
|
-
|
|
|
+
|
|
|
Method OnSemantType:Type( scope:Scope ) Override
|
|
|
|
|
|
- Local types:=SemantTypes( Self.types,scope )
|
|
|
-
|
|
|
Local type:=Self.expr.SemantType( scope,True )
|
|
|
|
|
|
- Return type.GenInstance( types )
|
|
|
+ Local args:=New Type[Self.args.Length]
|
|
|
+
|
|
|
+ For Local i:=0 Until args.Length
|
|
|
+ args[i]=Self.args[i].SemantType( scope )
|
|
|
+ Next
|
|
|
+
|
|
|
+ Return type.GenInstance( args )
|
|
|
End
|
|
|
|
|
|
+ Method ToString:String() Override
|
|
|
+
|
|
|
+ Return expr.ToString()+"<"+Join( args )+">"
|
|
|
+ End
|
|
|
End
|
|
|
|
|
|
Class NewObjectExpr Extends Expr
|
|
|
|
|
|
- Field type:TypeExpr
|
|
|
+ Field type:Expr
|
|
|
Field args:Expr[]
|
|
|
|
|
|
- Method New( type:TypeExpr,args:Expr[],srcpos:Int,endpos:Int )
|
|
|
+ Method New( type:Expr,args:Expr[],srcpos:Int,endpos:Int )
|
|
|
Super.New( srcpos,endpos )
|
|
|
|
|
|
Self.type=type
|
|
|
Self.args=args
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- Local str:="New "+type.ToString()
|
|
|
- If args str+="("+Join( args )+")"
|
|
|
- Return str
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
- Local type:=Self.type.Semant( scope )
|
|
|
+ Local type:=Self.type.SemantType( scope )
|
|
|
|
|
|
Local ctype:=TCast<ClassType>( type )
|
|
|
If Not ctype Throw New SemantEx( "Type '"+type.Name+"' is not a class" )
|
|
@@ -348,6 +352,13 @@ Class NewObjectExpr Extends Expr
|
|
|
|
|
|
Return New NewObjectValue( ctype,ctorFunc,args )
|
|
|
End
|
|
|
+
|
|
|
+ Method ToString:String() Override
|
|
|
+ Local str:="New "+type.ToString()
|
|
|
+ If args str+="("+Join( args )+")"
|
|
|
+ Return str
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
Class NewArrayExpr Extends Expr
|
|
@@ -364,14 +375,9 @@ Class NewArrayExpr Extends Expr
|
|
|
Self.inits=inits
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- If sizes Return "New "+type.type.ToString()+"["+Join( sizes )+"]"
|
|
|
- Return "New "+type.ToString()+"("+Join( inits )+")"
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
- Local atype:=TCast<ArrayType>( type.Semant( scope ) )
|
|
|
+ Local atype:=TCast<ArrayType>( type.SemantType( scope ) )
|
|
|
If Not atype SemantError( "NewArrayExpr.OnSemant()" )
|
|
|
|
|
|
If atype.elemType.IsGeneric Throw New SemantEx( "Array element type '"+atype.elemType.Name+"' is generic" )
|
|
@@ -392,6 +398,13 @@ Class NewArrayExpr Extends Expr
|
|
|
Return New NewArrayValue( atype,sizes,inits )
|
|
|
End
|
|
|
|
|
|
+ Method ToString:String() Override
|
|
|
+
|
|
|
+ If sizes Return "New "+type.type.ToString()+"["+Join( sizes )+"]"
|
|
|
+
|
|
|
+ Return "New "+type.ToString()+"("+Join( inits )+")"
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
Class IndexExpr Extends Expr
|
|
@@ -405,10 +418,6 @@ Class IndexExpr Extends Expr
|
|
|
Self.args=args
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- Return expr.ToString()+"["+Join( args )+"]"
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
Local value:=expr.Semant( scope )
|
|
@@ -418,15 +427,19 @@ Class IndexExpr Extends Expr
|
|
|
Return value.Index( args )
|
|
|
End
|
|
|
|
|
|
+ Method ToString:String() Override
|
|
|
+
|
|
|
+ Return expr.ToString()+"["+Join( args )+"]"
|
|
|
+ End
|
|
|
End
|
|
|
|
|
|
Class ExtendsExpr Extends Expr
|
|
|
|
|
|
Field op:String
|
|
|
Field expr:Expr
|
|
|
- Field type:TypeExpr
|
|
|
+ Field type:Expr
|
|
|
|
|
|
- Method New( op:String,expr:Expr,type:TypeExpr,srcpos:Int,endpos:Int )
|
|
|
+ Method New( op:String,expr:Expr,type:Expr,srcpos:Int,endpos:Int )
|
|
|
Super.New( srcpos,endpos )
|
|
|
Self.op=op
|
|
|
Self.expr=expr
|
|
@@ -435,7 +448,7 @@ Class ExtendsExpr Extends Expr
|
|
|
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
- Local ctype:=TCast<ClassType>( Self.type.Semant( scope ) )
|
|
|
+ Local ctype:=TCast<ClassType>( Self.type.SemantType( scope ) )
|
|
|
If Not ctype Or (ctype.cdecl.kind<>"class" And ctype.cdecl.kind<>"interface" And ctype.cdecl.kind<>"protocol" )
|
|
|
Throw New SemantEx( "Type '"+type.ToString()+"' is not a class or interface type" )
|
|
|
Endif
|
|
@@ -461,37 +474,37 @@ Class ExtendsExpr Extends Expr
|
|
|
|
|
|
Method OnSemantWhere:Bool( scope:Scope ) Override
|
|
|
|
|
|
- Local ctype:=TCast<ClassType>( Self.type.Semant( scope ) )
|
|
|
+ Local ctype:=TCast<ClassType>( Self.type.SemantType( scope ) )
|
|
|
|
|
|
If Not ctype Or (ctype.cdecl.kind<>"class" And ctype.cdecl.kind<>"interface" And ctype.cdecl.kind<>"protocol" )
|
|
|
Throw New SemantEx( "Type '"+type.ToString()+"' is not a class or interface type" )
|
|
|
- endif
|
|
|
+ Endif
|
|
|
|
|
|
Local type:=Self.expr.SemantType( scope )
|
|
|
|
|
|
Return type.ExtendsType( ctype )
|
|
|
End
|
|
|
-
|
|
|
+
|
|
|
+ Method ToString:String() Override
|
|
|
+
|
|
|
+ Return expr.ToString()+" "+op.Capitalize()+" "+type.ToString()
|
|
|
+ End
|
|
|
End
|
|
|
|
|
|
Class CastExpr Extends Expr
|
|
|
|
|
|
- Field type:TypeExpr
|
|
|
+ Field type:Expr
|
|
|
Field expr:Expr
|
|
|
|
|
|
- Method New( type:TypeExpr,expr:Expr,srcpos:Int,endpos:Int )
|
|
|
+ Method New( type:Expr,expr:Expr,srcpos:Int,endpos:Int )
|
|
|
Super.New( srcpos,endpos )
|
|
|
Self.type=type
|
|
|
Self.expr=expr
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- Return "cast<"+type.ToString()+">("+expr.ToString()+")"
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
- Local type:=Self.type.Semant( scope )
|
|
|
+ Local type:=Self.type.SemantType( scope )
|
|
|
|
|
|
Local value:=Self.expr.Semant( scope )
|
|
|
|
|
@@ -512,6 +525,11 @@ Class CastExpr Extends Expr
|
|
|
Return New ExplicitCastValue( type,value )
|
|
|
End
|
|
|
|
|
|
+ Method ToString:String() Override
|
|
|
+
|
|
|
+ Return "Cast<"+type.ToString()+">("+expr.ToString()+")"
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
Class SelfExpr Extends Expr
|
|
@@ -520,10 +538,6 @@ Class SelfExpr Extends Expr
|
|
|
Super.New( srcpos,endpos )
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- Return "self"
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
Local block:=Cast<Block>( scope )
|
|
@@ -533,6 +547,11 @@ Class SelfExpr Extends Expr
|
|
|
Return Null
|
|
|
End
|
|
|
|
|
|
+ Method ToString:String() Override
|
|
|
+
|
|
|
+ Return "Self"
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
Class SuperExpr Extends Expr
|
|
@@ -541,10 +560,6 @@ Class SuperExpr Extends Expr
|
|
|
Super.New( srcpos,endpos )
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- Return "super"
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
Local block:=Cast<Block>( scope )
|
|
@@ -565,6 +580,10 @@ Class SuperExpr Extends Expr
|
|
|
Return Null
|
|
|
End
|
|
|
|
|
|
+ Method ToString:String() Override
|
|
|
+ Return "Super"
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
Class NullExpr Extends Expr
|
|
@@ -573,14 +592,14 @@ Class NullExpr Extends Expr
|
|
|
Super.New( srcpos,endpos )
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- Return "null"
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
Return New NullValue
|
|
|
End
|
|
|
|
|
|
+ Method ToString:String() Override
|
|
|
+ Return "Null"
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
Class UnaryopExpr Extends Expr
|
|
@@ -594,10 +613,6 @@ Class UnaryopExpr Extends Expr
|
|
|
Self.expr=expr
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- Return op+expr.ToString()
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
Local value:=expr.SemantRValue( scope )
|
|
@@ -633,6 +648,10 @@ Class UnaryopExpr Extends Expr
|
|
|
Return EvalUnaryop( type,op,value.UpCast( type ) )
|
|
|
End
|
|
|
|
|
|
+ Method ToString:String() Override
|
|
|
+ Return op.Capitalize()+expr.ToString()
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
Class BinaryopExpr Extends Expr
|
|
@@ -647,67 +666,7 @@ Class BinaryopExpr Extends Expr
|
|
|
Self.lhs=lhs
|
|
|
Self.rhs=rhs
|
|
|
End
|
|
|
-
|
|
|
- Method ToString:String() Override
|
|
|
- Return "("+lhs.ToString()+op+rhs.ToString()+")"
|
|
|
- End
|
|
|
-
|
|
|
- Function BalanceIntegralTypes:Type( lhs:PrimType,rhs:PrimType )
|
|
|
-
|
|
|
- If Not lhs Or Not rhs Or Not lhs.IsIntegral Or Not rhs.IsIntegral
|
|
|
- Throw New SemantEx( "Types must be integral" )
|
|
|
- Endif
|
|
|
-
|
|
|
- 'Think about this more...!
|
|
|
- '
|
|
|
- If lhs=Type.ULongType Or rhs=Type.ULongType Return Type.ULongType
|
|
|
-
|
|
|
- If lhs=Type.LongType Or rhs=Type.LongType Return Type.LongType
|
|
|
-
|
|
|
- If lhs.IsUnsignedIntegral Or rhs.IsUnsignedIntegral Return Type.UIntType
|
|
|
-
|
|
|
- Return Type.IntType
|
|
|
- End
|
|
|
-
|
|
|
- function BalanceNumericTypes:Type( lhs:PrimType,rhs:PrimType )
|
|
|
-
|
|
|
- If Not lhs Or Not rhs Or Not lhs.IsNumeric Or Not rhs.IsNumeric
|
|
|
- Throw New SemantEx( "Types must be numeric" )
|
|
|
- Endif
|
|
|
-
|
|
|
- If lhs=Type.DoubleType Or rhs=Type.DoubleType Return Type.DoubleType
|
|
|
|
|
|
- If lhs=Type.FloatType Or rhs=Type.FloatType Return Type.FloatType
|
|
|
-
|
|
|
- Return BalanceIntegralTypes( lhs,rhs )
|
|
|
- End
|
|
|
-
|
|
|
- function BalancePrimTypes:Type( lhs:PrimType,rhs:PrimType )
|
|
|
-
|
|
|
- If Not lhs Or Not rhs
|
|
|
- Throw New SemantEx( "Types must be primitive" )
|
|
|
- Endif
|
|
|
-
|
|
|
- If lhs=Type.StringType Or rhs=Type.StringType Return Type.StringType
|
|
|
-
|
|
|
- Return BalanceNumericTypes( lhs,rhs )
|
|
|
- End
|
|
|
-
|
|
|
- Function BalanceTypes:Type( lhs:Type,rhs:Type )
|
|
|
-
|
|
|
- Local plhs:=TCast<PrimType>( lhs )
|
|
|
- Local prhs:=TCast<PrimType>( rhs )
|
|
|
-
|
|
|
- If plhs And prhs Return BalancePrimTypes( plhs,prhs )
|
|
|
-
|
|
|
- If lhs.DistanceToType( rhs )>=0 Return rhs 'And rhs.DistanceToType( lhs )<=0 Return rhs
|
|
|
- If rhs.DistanceToType( lhs )>=0 Return lhs 'And lhs.DistanceToType( rhs )<=0 Return lhs
|
|
|
-
|
|
|
- Throw New SemantEx( "Types '"+lhs.Name+"' and '"+rhs.Name+"' are incompatible" )
|
|
|
-
|
|
|
- Return Null
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
Local lhs:=Self.lhs.Semant( scope )
|
|
@@ -724,115 +683,30 @@ Class BinaryopExpr Extends Expr
|
|
|
rhs=rhs.ToRValue()
|
|
|
Endif
|
|
|
|
|
|
- 'check for overloaded operator
|
|
|
+ 'check for overloadeded operator
|
|
|
'
|
|
|
Local node:=lhs.FindValue( op )
|
|
|
If node
|
|
|
- Local args:=New Value[1]
|
|
|
- args[0]=rhs
|
|
|
- Return node.Invoke( args )
|
|
|
- Endif
|
|
|
-
|
|
|
- 'handle pointer arithmetic
|
|
|
- '
|
|
|
- Local lptype:=TCast<PointerType>( lhs.type )
|
|
|
- Local rptype:=TCast<PointerType>( rhs.type )
|
|
|
- If lptype Or rptype
|
|
|
- If lptype And (op="+" Or op="-")
|
|
|
- 'pointer=pointer +/- int
|
|
|
- Return New BinaryopValue( lptype,op,lhs,rhs.UpCast( Type.IntType ) )
|
|
|
- Else If rptype And op="+"
|
|
|
- 'pointer=int + pointer
|
|
|
- Return New BinaryopValue( rptype,op,rhs,lhs.UpCast( Type.IntType ) )
|
|
|
- Endif
|
|
|
- Throw New SemantEx( "Pointer arithmetic error" )
|
|
|
+ Return node.Invoke( New Value[]( rhs ) )
|
|
|
Endif
|
|
|
|
|
|
- Local plhs:=TCast<PrimType>( lhs.type )
|
|
|
- Local prhs:=TCast<PrimType>( rhs.type )
|
|
|
-
|
|
|
- Local type:Type,lhsType:Type,rhsType:Type
|
|
|
-
|
|
|
+ 'check for overloaded <=> for comparisons
|
|
|
+ '
|
|
|
Select op
|
|
|
- Case "+"
|
|
|
-
|
|
|
- type=BalancePrimTypes( plhs,prhs )
|
|
|
-
|
|
|
- Case "*","/","mod","-"
|
|
|
-
|
|
|
- type=BalanceNumericTypes( plhs,prhs )
|
|
|
-
|
|
|
- Case "&","|","~"
|
|
|
-
|
|
|
- Local elhs:=TCast<EnumType>( lhs.type )
|
|
|
- Local erhs:=TCast<EnumType>( rhs.type )
|
|
|
- If elhs Or erhs
|
|
|
- If elhs.Equals( erhs ) type=elhs
|
|
|
- Else
|
|
|
- type=BalanceIntegralTypes( plhs,prhs )
|
|
|
- Endif
|
|
|
-
|
|
|
- Case "shl","shr"
|
|
|
-
|
|
|
- type=BalanceIntegralTypes( plhs,plhs )
|
|
|
- rhsType=Type.IntType
|
|
|
-
|
|
|
Case "=","<>","<",">","<=",">="
|
|
|
-
|
|
|
Local node:=lhs.FindValue( "<=>" )
|
|
|
If node
|
|
|
-
|
|
|
- Local args:=New Value[1]
|
|
|
- args[0]=rhs
|
|
|
- lhs=node.Invoke( args )
|
|
|
-
|
|
|
- lhsType=lhs.type
|
|
|
- rhsType=lhsType
|
|
|
-
|
|
|
- Local ptype:=TCast<PrimType>( lhsType )
|
|
|
- Assert( ptype And ptype.IsNumeric )
|
|
|
-
|
|
|
- rhs=New LiteralValue( rhsType,"" )
|
|
|
- type=Type.BoolType
|
|
|
-
|
|
|
- Else If plhs=Type.BoolType Or prhs=Type.BoolType
|
|
|
-
|
|
|
- If op<>"=" And op<>"<>" Throw New SemantEx( "Bool values can only be compared for equality" )
|
|
|
-
|
|
|
- type=Type.BoolType
|
|
|
-
|
|
|
- Else
|
|
|
-
|
|
|
- type=BalanceTypes( lhs.type,rhs.type )
|
|
|
- If type
|
|
|
- lhsType=type
|
|
|
- rhsType=type
|
|
|
- type=Type.BoolType
|
|
|
- Endif
|
|
|
-
|
|
|
-
|
|
|
+ lhs=node.Invoke( New Value[]( rhs ) )
|
|
|
+ rhs=New LiteralValue( lhs.type,"" ) 'compare with '0'.
|
|
|
Endif
|
|
|
-
|
|
|
- Case "<=>"
|
|
|
-
|
|
|
- type=BalanceTypes( lhs.type,rhs.type )
|
|
|
- If type
|
|
|
- lhsType=type
|
|
|
- rhsType=type
|
|
|
- type=Type.IntType
|
|
|
- Endif
|
|
|
-
|
|
|
- Case "and","or"
|
|
|
-
|
|
|
- type=Type.BoolType
|
|
|
End
|
|
|
|
|
|
- If Not type Throw New SemantEx( "Parameter types for binary operator '"+op+"' cannot be determined" )
|
|
|
+ Local argTypes:=New Type[2]
|
|
|
+ Local type:=BalanceBinaryopTypes( op,lhs.type,rhs.type,argTypes )
|
|
|
|
|
|
- If Not lhsType lhsType=type
|
|
|
- If Not rhsType rhsType=type
|
|
|
+ If Not type Throw New SemantEx( "Parameter types for binary operator '"+op+"' cannot be determined" )
|
|
|
|
|
|
- Return EvalBinaryop( type,op,lhs.UpCast( lhsType ),rhs.UpCast( rhsType ) )
|
|
|
+ Return EvalBinaryop( type,op,lhs.UpCast( argTypes[0] ),rhs.UpCast( argTypes[1] ) )
|
|
|
End
|
|
|
|
|
|
Method OnSemantWhere:Bool( scope:Scope ) Override
|
|
@@ -847,6 +721,10 @@ Class BinaryopExpr Extends Expr
|
|
|
Return Not lhs.Equals( rhs )
|
|
|
End
|
|
|
|
|
|
+ Method ToString:String() Override
|
|
|
+
|
|
|
+ Return "("+lhs.ToString()+op+rhs.ToString()+")"
|
|
|
+ End
|
|
|
End
|
|
|
|
|
|
Class IfThenElseExpr Extends Expr
|
|
@@ -865,15 +743,28 @@ Class IfThenElseExpr Extends Expr
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
Local value:=expr.SemantRValue( scope,Type.BoolType )
|
|
|
- Local thenValue:=thenExpr.SemantRValue( scope )
|
|
|
- Local elseValue:=elseExpr.SemantRValue( scope )
|
|
|
|
|
|
- Local type:=BinaryopExpr.BalanceTypes( thenValue.type,elseValue.type )
|
|
|
+ Local thenValue:=thenExpr.Semant( scope )
|
|
|
+ Local elseValue:=elseExpr.Semant( scope )
|
|
|
+
|
|
|
+ If thenValue.type=Type.NullType
|
|
|
+ elseValue=elseValue.ToRValue()
|
|
|
+ thenValue=thenValue.UpCast( elseValue.type )
|
|
|
+ Else If elseValue.type=Type.NullType
|
|
|
+ thenValue=thenValue.ToRValue()
|
|
|
+ elseValue=elseValue.UpCast( thenValue.type )
|
|
|
+ Endif
|
|
|
+
|
|
|
+ Local type:=BalanceTypes( thenValue.type,elseValue.type )
|
|
|
thenValue=thenValue.UpCast( type )
|
|
|
elseValue=elseValue.UpCast( type )
|
|
|
|
|
|
Return New IfThenElseValue( type,value,thenValue,elseValue )
|
|
|
End
|
|
|
+
|
|
|
+ Method ToString:String() Override
|
|
|
+ Return "("+expr.ToString()+" ? "+thenExpr.ToString()+" Else "+elseExpr.ToString()+")"
|
|
|
+ End
|
|
|
End
|
|
|
|
|
|
Class VarptrExpr Extends Expr
|
|
@@ -885,10 +776,6 @@ Class VarptrExpr Extends Expr
|
|
|
Self.expr=expr
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- Return "Varptr "+expr.ToString()
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
Local value:=expr.Semant( scope )
|
|
@@ -897,32 +784,33 @@ Class VarptrExpr Extends Expr
|
|
|
|
|
|
Return New PointerValue( value )
|
|
|
End
|
|
|
+
|
|
|
+ Method ToString:String() Override
|
|
|
+ Return "Varptr "+expr.ToString()
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
Class LiteralExpr Extends Expr
|
|
|
|
|
|
Field toke:String
|
|
|
Field tokeType:Int
|
|
|
- Field typeExpr:TypeExpr
|
|
|
+ Field typeExpr:Expr
|
|
|
|
|
|
- Method New( toke:String,tokeType:Int,typeExpr:TypeExpr,srcpos:Int,endpos:Int )
|
|
|
+ Method New( toke:String,tokeType:Int,typeExpr:Expr,srcpos:Int,endpos:Int )
|
|
|
Super.New( srcpos,endpos )
|
|
|
Self.toke=toke
|
|
|
Self.tokeType=tokeType
|
|
|
Self.typeExpr=typeExpr
|
|
|
End
|
|
|
|
|
|
- Method ToString:String() Override
|
|
|
- Return toke
|
|
|
- End
|
|
|
-
|
|
|
Method OnSemant:Value( scope:Scope ) Override
|
|
|
|
|
|
Local type:Type
|
|
|
|
|
|
If typeExpr
|
|
|
|
|
|
- type=typeExpr.Semant( scope )
|
|
|
+ type=typeExpr.SemantType( scope )
|
|
|
|
|
|
Local ptype:=TCast<PrimType>( type )
|
|
|
If Not ptype Throw New SemantEx( "Literal type must be a primitive type" )
|
|
@@ -982,44 +870,107 @@ Class LiteralExpr Extends Expr
|
|
|
|
|
|
Return New LiteralValue( type,t )
|
|
|
End
|
|
|
+
|
|
|
+ Method ToString:String() Override
|
|
|
+ Return toke
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
-Class ArrayLiteralExpr Extends Expr
|
|
|
+Class LambdaExpr Extends Expr
|
|
|
|
|
|
- Field exprs:Expr[]
|
|
|
+ Field decl:FuncDecl
|
|
|
|
|
|
- Method New( exprs:Expr[],srcpos:Int,endpos:Int )
|
|
|
+ Method New( decl:FuncDecl,srcpos:Int,endpos:Int )
|
|
|
Super.New( srcpos,endpos )
|
|
|
+ Self.decl=decl
|
|
|
+ End
|
|
|
+
|
|
|
+ Method OnSemant:Value( scope:Scope ) Override
|
|
|
+
|
|
|
+ Local func:=New FuncValue( decl,scope,Null,Null )
|
|
|
|
|
|
- Self.exprs=exprs
|
|
|
+ func.Semant()
|
|
|
+
|
|
|
+ Return func
|
|
|
End
|
|
|
|
|
|
Method ToString:String() Override
|
|
|
- Return "["+Join( exprs )+"]"
|
|
|
+ Return decl.ToString()
|
|
|
+ End
|
|
|
+End
|
|
|
+
|
|
|
+Class ArrayTypeExpr Extends Expr
|
|
|
+
|
|
|
+ Field type:Expr
|
|
|
+ Field rank:Int
|
|
|
+
|
|
|
+ Method New( type:Expr,rank:Int,srcpos:Int,endpos:Int )
|
|
|
+ Super.New( srcpos,endpos )
|
|
|
+ Self.type=type
|
|
|
+ Self.rank=rank
|
|
|
+ End
|
|
|
+
|
|
|
+ Method OnSemantType:Type( scope:Scope ) Override
|
|
|
+
|
|
|
+ Local type:=Self.type.SemantType( scope )
|
|
|
+
|
|
|
+ Return New ArrayType( type,rank )
|
|
|
End
|
|
|
|
|
|
+ Method ToString:String() Override
|
|
|
+ Return type.ToString()+"[,,,,,,,,,,,".Slice( 0,rank )+"]"
|
|
|
+ End
|
|
|
+
|
|
|
End
|
|
|
|
|
|
-Class LambdaExpr Extends Expr
|
|
|
+Class FuncTypeExpr Extends Expr
|
|
|
|
|
|
- Field decl:FuncDecl
|
|
|
+ Field retType:Expr
|
|
|
+ Field params:VarDecl[]
|
|
|
|
|
|
- Method New( decl:FuncDecl,srcpos:Int,endpos:Int )
|
|
|
+ Method New( retType:Expr,params:VarDecl[],srcpos:Int,endpos:Int )
|
|
|
Super.New( srcpos,endpos )
|
|
|
- Self.decl=decl
|
|
|
+ Self.retType=retType
|
|
|
+ Self.params=params
|
|
|
+ End
|
|
|
+
|
|
|
+ Method OnSemantType:Type( scope:Scope ) Override
|
|
|
+
|
|
|
+ Local retType:=Self.retType.SemantType( scope )
|
|
|
+
|
|
|
+ Local argTypes:=New Type[params.Length]
|
|
|
+ For Local i:=0 Until argTypes.Length
|
|
|
+ argTypes[i]=params[i].type.SemantType( scope )
|
|
|
+ Next
|
|
|
+
|
|
|
+ Return New FuncType( retType,argTypes )
|
|
|
End
|
|
|
|
|
|
Method ToString:String() Override
|
|
|
- Return decl.ToString()
|
|
|
+ Return retType.ToString()+"("+Join( params )+")"
|
|
|
End
|
|
|
+
|
|
|
+End
|
|
|
+
|
|
|
+Class PointerTypeExpr Extends Expr
|
|
|
+
|
|
|
+ Field type:Expr
|
|
|
|
|
|
- Method OnSemant:Value( scope:Scope ) Override
|
|
|
-
|
|
|
- Local func:=New FuncValue( decl,scope,Null,Null )
|
|
|
-
|
|
|
- func.Semant()
|
|
|
+ Method New( type:Expr,srcpos:Int,endpos:Int )
|
|
|
+ Super.New( srcpos,endpos )
|
|
|
|
|
|
- Return func
|
|
|
+ Self.type=type
|
|
|
End
|
|
|
|
|
|
+ Method OnSemantType:Type( scope:Scope ) Override
|
|
|
+
|
|
|
+ Local type:=Self.type.SemantType( scope )
|
|
|
+
|
|
|
+ Return New PointerType( type )
|
|
|
+ End
|
|
|
+
|
|
|
+ Method ToString:String() Override
|
|
|
+ Return type.ToString()+" Ptr"
|
|
|
+ End
|
|
|
End
|