|
@@ -6,8 +6,26 @@ Class ClassDecl Extends Decl
|
|
|
Field genArgs:String[]
|
|
|
Field superType:Expr
|
|
|
Field ifaceTypes:Expr[]
|
|
|
+ Field hasCtor:Bool=False
|
|
|
+ Field hasDefaultCtor:Bool=True
|
|
|
|
|
|
Method ToNode:SNode( scope:Scope ) Override
|
|
|
+
|
|
|
+ hasCtor=False
|
|
|
+ For Local decl:=Eachin members
|
|
|
+ Local fdecl:=Cast<FuncDecl>( decl )
|
|
|
+ If Not fdecl Or fdecl.ident<>"new" Continue
|
|
|
+ hasCtor=True
|
|
|
+ Local isdefault:=True
|
|
|
+ For Local pdecl:=Eachin fdecl.type.params
|
|
|
+ If pdecl.init Continue
|
|
|
+ isdefault=False
|
|
|
+ Exit
|
|
|
+ Next
|
|
|
+ If Not isdefault Continue
|
|
|
+ hasDefaultCtor=True
|
|
|
+ Exit
|
|
|
+ Next
|
|
|
|
|
|
Local types:=New Type[genArgs.Length]
|
|
|
For Local i:=0 Until types.Length
|
|
@@ -53,7 +71,7 @@ Class ClassType Extends Type
|
|
|
Field fields:=New Stack<VarValue>
|
|
|
|
|
|
Field extendsVoid:Bool
|
|
|
- Field hasDefaultCtor:Bool
|
|
|
+ Field defaultCtor:FuncValue
|
|
|
|
|
|
Method New( cdecl:ClassDecl,outer:Scope,types:Type[],instanceOf:ClassType )
|
|
|
|
|
@@ -231,8 +249,11 @@ Class ClassType Extends Type
|
|
|
SemantMembers()
|
|
|
|
|
|
Builder.semantingModule.genInstances.Push( Self )
|
|
|
+
|
|
|
Else
|
|
|
+
|
|
|
Builder.semantMembers.AddLast( Self )
|
|
|
+
|
|
|
Endif
|
|
|
|
|
|
transFile.classes.Push( Self )
|
|
@@ -243,7 +264,7 @@ Class ClassType Extends Type
|
|
|
End
|
|
|
|
|
|
Method SemantMembers()
|
|
|
-
|
|
|
+
|
|
|
If membersSemanted Return
|
|
|
|
|
|
If membersSemanting SemantError( "ClassType.SemantMembers()" )
|
|
@@ -275,25 +296,6 @@ Class ClassType Extends Type
|
|
|
|
|
|
Next
|
|
|
|
|
|
- 'default ctor check
|
|
|
- '
|
|
|
- Local flist:=Cast<FuncList>( scope.GetNode( "new" ) )
|
|
|
- If flist
|
|
|
- hasDefaultCtor=False
|
|
|
- For Local func:=Eachin flist.funcs
|
|
|
- If func.ftype.argTypes Continue
|
|
|
- hasDefaultCtor=True
|
|
|
- Next
|
|
|
- Else If Not cdecl.IsExtension
|
|
|
- If superType And Not superType.hasDefaultCtor
|
|
|
- Try
|
|
|
- Throw New SemantEx( "Super class '"+superType.Name+"' has no default constructor" )
|
|
|
- Catch ex:SemantEx
|
|
|
- End
|
|
|
- Endif
|
|
|
- hasDefaultCtor=True
|
|
|
- Endif
|
|
|
-
|
|
|
If (cdecl.kind="class" Or cdecl.kind="struct") And Not scope.IsGeneric
|
|
|
|
|
|
'Enum unimplemented superclass abstract methods
|
|
@@ -347,13 +349,45 @@ Class ClassType Extends Type
|
|
|
Endif
|
|
|
|
|
|
Endif
|
|
|
-
|
|
|
+
|
|
|
Self.abstractMethods=abstractMethods.ToArray()
|
|
|
|
|
|
'Finished semanting funcs
|
|
|
'
|
|
|
membersSemanting=False
|
|
|
membersSemanted=True
|
|
|
+
|
|
|
+ 'default ctor check
|
|
|
+ '
|
|
|
+ If Not cdecl.IsExtension And superType And Not superType.cdecl.hasDefaultCtor
|
|
|
+ Local flist:=Cast<FuncList>( scope.GetNode( "new" ) )
|
|
|
+ If Not flist New SemantEx( "Super class '"+superType.Name+"' has no default constructor!!!!" )
|
|
|
+ Endif
|
|
|
+
|
|
|
+ #rem
|
|
|
+ If flist
|
|
|
+ For Local func:=Eachin flist.funcs
|
|
|
+ hasDefaultCtor=True
|
|
|
+ If func.params
|
|
|
+ For Local p:=Eachin func.params
|
|
|
+ If p.init Continue
|
|
|
+ hasDefaultCtor=False
|
|
|
+ Exit
|
|
|
+ Next
|
|
|
+ If Not hasDefaultCtor Continue
|
|
|
+ Endif
|
|
|
+ Exit
|
|
|
+ Next
|
|
|
+ Else If Not cdecl.IsExtension
|
|
|
+ If superType
|
|
|
+ superType.scope.GetNode( "new" )
|
|
|
+ If Not superType.hasDefaultCtor
|
|
|
+ New SemantEx( "Super class '"+superType.Name+"' has no default constructor" )
|
|
|
+ Endif
|
|
|
+ Endif
|
|
|
+ hasDefaultCtor=True
|
|
|
+ Endif
|
|
|
+ #end
|
|
|
|
|
|
'Semant non-func members
|
|
|
'
|