Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Arpad Lovassy
titan.EclipsePlug-ins
Commits
dee75b40
Commit
dee75b40
authored
May 20, 2022
by
Miklos Magyari
Committed by
Adam Knapp
May 20, 2022
Browse files
OOP: synch with titan core (7) (issue
#487
)
parent
b9d67b60
Changes
10
Hide whitespace changes
Inline
Side-by-side
Semantic_Analizer_Tests/src/Basic_tests/OopTests.ttcn
0 → 100755
View file @
dee75b40
module
OopTests
{
type
class
BaseClass
{
var
integer
x
;
}
type
class
@
trait
BaseClass1
{
}
type
class
BaseClass2
{
}
type
class
BaseClass3
{
}
type
class
@
final
BaseClass4
{
}
type
class
BaseClass5
{
public
function
func
()
{
};
function
func2
()
{
}
var
integer
int1
;
}
type
record
MyRec
{
}
// wrong: a class can extend at most one non-trai class
type
class
Child1
extends
BaseClass
,
BaseClass2
,
BaseClass3
{
}
// wrong: a class can only extend other classes
type
class
Child2
extends
BaseClass
,
BaseClass1
,
MyRec
{
}
// wrong: not allowed to add more than one of @final, @abstract or @trait
type
class
@
abstract
@
trait
Modifiers1
{
}
type
class
@
abstract
@
final
Modifiers2
{
}
type
class
@
trait
@
final
Modifiers3
{
}
// wrong: a trait class cannot extend a non-trait class
type
class
@
trait
TraitExtend
extends
BaseClass2
{
}
// wrong: external class cannot be abstract
type
external
class
@
abstract
ExtAbs
{
}
// wrong: base class cannot be final
type
class
ExtFinal
extends
BaseClass4
{
}
type
class
ExtObj
{
// wrong: incomplatible override of object's equal method
public
function
equals
(
integer
par1
);
// wrong: incomplatible override of object's equal method
public
function
toString
()
return
float
{
return
0.1
;
}
}
type
class
Child3
extends
BaseClass5
{
var
integer
member1
;
// wrong: shadows member from parent
var
integer
int1
;
// wrong: public method can only be overriden as public
private
function
func
()
{
}
function
func
()
{
}
// wrong: protected method can only be overriden as public/protected
private
function
func2
()
{
}
}
}
org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/Assignment.java
View file @
dee75b40
...
...
@@ -26,6 +26,7 @@ import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
* All TTCN3 definitions extend this class.
*
* @author Kristof Szabados
* @author Miklos Magyari
* */
public
abstract
class
Assignment
extends
ASTNode
implements
IOutlineElement
,
ILocateableNode
,
IReferenceChainElement
,
IReferencingElement
{
protected
static
final
String
GLOBALLY_UNUSED
=
"The {0} seems to be never used globally"
;
...
...
@@ -103,6 +104,7 @@ public abstract class Assignment extends ASTNode implements IOutlineElement, ILo
private
boolean
canBeCheckRoot
=
true
;
protected
VisibilityModifier
visibility
;
protected
Location
visibilityLocation
;
public
Assignment
(
final
Identifier
identifier
)
{
this
.
identifier
=
identifier
;
...
...
org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/Reference.java
View file @
dee75b40
...
...
@@ -167,6 +167,21 @@ public class Reference extends ASTNode implements ILocateableNode, IIncrementall
this
(
modid
,
subReferences
);
this
.
reftype
=
reftype
;
}
public
Reference
(
final
Identifier
modid
,
final
Identifier
referencedId
)
{
final
FieldSubReference
fieldsubref
=
new
FieldSubReference
(
referencedId
);
final
List
<
ISubReference
>
subrefs
=
new
ArrayList
<>(
1
);
subrefs
.
add
(
fieldsubref
);
this
.
modid
=
modid
;
detectedModuleId
=
modid
!=
null
;
this
.
subReferences
=
new
ArrayList
<
ISubReference
>(
subReferences
);
this
.
subReferences
.
trimToSize
();
for
(
int
i
=
0
;
i
<
subReferences
.
size
();
i
++)
{
subReferences
.
get
(
i
).
setFullNameParent
(
this
);
}
}
/** @return a new instance of this reference */
public
Reference
newInstance
()
{
...
...
org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_AbsFunction.java
View file @
dee75b40
...
...
@@ -13,6 +13,7 @@ import org.eclipse.titan.designer.AST.Location;
import
org.eclipse.titan.designer.AST.Reference
;
import
org.eclipse.titan.designer.AST.Type
;
import
org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction
;
import
org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList.IsIdenticalResult
;
import
org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock
;
import
org.eclipse.titan.designer.AST.TTCN3.types.SignatureExceptions
;
import
org.eclipse.titan.designer.compiler.JavaGenData
;
...
...
@@ -25,9 +26,11 @@ import org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater;
*
* @author Miklos Magyari
*/
public
class
Def_AbsFunction
extends
Definition
implements
IParameterisedAssignment
{
public
class
Def_AbsFunction
extends
Definition
implements
IParameterisedAssignment
,
IFunctionBase
{
private
Type
returnType
;
private
Location
signatureLocation
=
null
;
private
boolean
isFinal
;
private
boolean
isAbstract
;
public
Def_AbsFunction
(
final
Identifier
identifier
,
final
FormalParameterList
formalParameters
,
final
Reference
runsOnRef
,
final
Reference
mtcReference
,
final
Reference
systemReference
,
final
Reference
portReference
,
...
...
@@ -36,13 +39,17 @@ public class Def_AbsFunction extends Definition implements IParameterisedAssignm
final
boolean
isClassFunction
,
final
boolean
isAbstract
,
final
boolean
isFinal
,
final
Location
classModifierLocation
,
final
boolean
isDeterministic
,
final
boolean
isControl
,
final
Location
funcModifierLocation
)
{
super
(
identifier
);
this
.
isFinal
=
isFinal
;
this
.
isAbstract
=
isAbstract
;
// TODO Auto-generated constructor stub
}
@Override
public
Location
getSignatureLocation
()
{
return
signatureLocation
;
}
@Override
public
void
setSignatureLocation
(
Location
signatureLocation
)
{
this
.
signatureLocation
=
signatureLocation
;
}
...
...
@@ -55,6 +62,16 @@ public class Def_AbsFunction extends Definition implements IParameterisedAssignm
return
"function_return.gif"
;
}
@Override
public
boolean
isFinal
()
{
return
isFinal
;
}
@Override
public
boolean
isAbstract
()
{
return
isAbstract
;
}
@Override
public
FormalParameterList
getFormalParameterList
()
{
...
...
@@ -104,4 +121,9 @@ public class Def_AbsFunction extends Definition implements IParameterisedAssignm
}
@Override
public
IsIdenticalResult
isIdentical
(
CompilationTimeStamp
timestamp
,
IFunctionBase
other
)
{
// TODO Auto-generated method stub
return
null
;
}
}
org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Constructor.java
View file @
dee75b40
...
...
@@ -10,14 +10,22 @@ package org.eclipse.titan.designer.AST.TTCN3.definitions;
import
org.eclipse.titan.designer.AST.IReferenceChain
;
import
org.eclipse.titan.designer.AST.Identifier
;
import
org.eclipse.titan.designer.AST.Identifier.Identifier_type
;
import
org.eclipse.titan.designer.AST.Location
;
import
org.eclipse.titan.designer.AST.Reference
;
import
org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList.IsIdenticalResult
;
import
org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock
;
import
org.eclipse.titan.designer.compiler.JavaGenData
;
import
org.eclipse.titan.designer.parsers.CompilationTimeStamp
;
import
org.eclipse.titan.designer.parsers.ttcn3parser.ReParseException
;
import
org.eclipse.titan.designer.parsers.ttcn3parser.TTCN3ReparseUpdater
;
public
class
Def_Constructor
extends
Definition
{
/**
* Represents the constructor of a TTCN3 class
*
* @author Miklos Magyari
*
*/
public
class
Def_Constructor
extends
Definition
implements
IParameterisedAssignment
,
IFunctionBase
{
private
final
StatementBlock
statementBlock
;
public
Def_Constructor
(
FormalParameterList
fpl
,
Reference
baseCall
,
StatementBlock
sb
)
{
...
...
@@ -71,4 +79,40 @@ public class Def_Constructor extends Definition {
// TODO Auto-generated method stub
}
@Override
public
IsIdenticalResult
isIdentical
(
CompilationTimeStamp
timestamp
,
IFunctionBase
other
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
boolean
isFinal
()
{
// TODO Auto-generated method stub
return
false
;
}
@Override
public
boolean
isAbstract
()
{
// TODO Auto-generated method stub
return
false
;
}
@Override
public
Location
getSignatureLocation
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
FormalParameterList
getFormalParameterList
()
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
void
setSignatureLocation
(
Location
signatureLocation
)
{
// TODO Auto-generated method stub
}
}
org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Extfunction.java
View file @
dee75b40
...
...
@@ -49,6 +49,7 @@ import org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers;
import
org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute
;
import
org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type
;
import
org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function.EncodingPrototype_type
;
import
org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList.IsIdenticalResult
;
import
org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type
;
import
org.eclipse.titan.designer.compiler.JavaGenData
;
import
org.eclipse.titan.designer.compiler.ProjectSourceCompiler
;
...
...
@@ -72,7 +73,7 @@ import org.eclipse.ui.IEditorPart;
* @author Kristof Szabados
* @author Arpad Lovassy
* */
public
final
class
Def_Extfunction
extends
Definition
implements
IParameterisedAssignment
{
public
final
class
Def_Extfunction
extends
Definition
implements
IParameterisedAssignment
,
IFunctionBase
{
public
enum
ExternalFunctionEncodingType_type
{
/** manual encoding. */
MANUAL
,
...
...
@@ -101,6 +102,7 @@ public final class Def_Extfunction extends Definition implements IParameterisedA
private
String
encodingOptions
;
private
ErrorBehaviorList
errorBehaviorList
;
private
PrintingType
printingType
;
private
Location
signatureLocation
;
public
Def_Extfunction
(
final
Identifier
identifier
,
final
FormalParameterList
formalParameters
,
final
Type
returnType
,
final
boolean
returnsTemplate
,
final
TemplateRestriction
.
Restriction_type
templateRestriction
)
{
...
...
@@ -1261,4 +1263,32 @@ public final class Def_Extfunction extends Definition implements IParameterisedA
sb
.
append
(
indentation
).
append
(
ICommentable
.
COMMENT_END
).
append
(
indentation
);
return
sb
.
toString
();
}
@Override
public
Location
getSignatureLocation
()
{
return
signatureLocation
;
}
@Override
public
void
setSignatureLocation
(
Location
signatureLocation
)
{
this
.
signatureLocation
=
signatureLocation
;
}
@Override
public
IsIdenticalResult
isIdentical
(
CompilationTimeStamp
timestamp
,
IFunctionBase
other
)
{
// TODO Auto-generated method stub
return
null
;
}
@Override
public
boolean
isFinal
()
{
// TODO Auto-generated method stub
return
false
;
}
@Override
public
boolean
isAbstract
()
{
// TODO Auto-generated method stub
return
false
;
}
}
org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Def_Function.java
View file @
dee75b40
...
...
@@ -448,6 +448,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
return
portType
;
}
@Override
public
boolean
isAbstract
()
{
return
isAbstract
;
}
...
...
@@ -1632,6 +1633,7 @@ public final class Def_Function extends Definition implements IParameterisedAssi
return
signatureLocation
;
}
@Override
public
void
setSignatureLocation
(
Location
signatureLocation
)
{
this
.
signatureLocation
=
signatureLocation
;
}
...
...
org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/Definition.java
View file @
dee75b40
...
...
@@ -93,10 +93,6 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
protected
WithAttributesPath
withAttributesPath
=
null
;
protected
ErroneousAttributes
erroneousAttributes
=
null
;
/** The visibility modifier of the definition */
private
VisibilityModifier
visibilityModifier
;
private
Location
visibilityLocation
=
NULL_Location
.
INSTANCE
;
protected
String
genName
=
""
;
/** Indicates if the definition is inherited from a parent class */
...
...
@@ -161,23 +157,23 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
* @param location
*/
public
final
void
setVisibility
(
final
VisibilityModifier
modifier
,
Location
location
)
{
visibility
Modifier
=
modifier
;
visibility
=
modifier
;
visibilityLocation
=
location
;
}
public
final
void
setVisibility
(
final
VisibilityModifier
modifier
)
{
visibility
Modifier
=
modifier
;
visibility
=
modifier
;
}
/**
* @return the visibility modifier of this definition.
* */
public
final
VisibilityModifier
getVisibilityModifier
()
{
if
(
visibility
Modifier
==
null
)
{
return
VisibilityModifier
.
P
ublic
;
if
(
visibility
==
null
)
{
return
VisibilityModifier
.
P
rotected
;
}
return
visibility
Modifier
;
return
visibility
;
}
/**
...
...
@@ -622,7 +618,7 @@ public abstract class Definition extends Assignment implements IAppendableSyntax
return
result
;
}
if
(
visibility
Modifier
==
null
)
{
if
(
visibility
==
null
)
{
final
List
<
Integer
>
result
=
new
ArrayList
<
Integer
>(
3
);
result
.
add
(
Ttcn3Lexer
.
PUBLIC
);
result
.
add
(
Ttcn3Lexer
.
FRIEND
);
...
...
org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/definitions/IFunctionBase.java
View file @
dee75b40
...
...
@@ -17,13 +17,20 @@ import org.eclipse.titan.designer.parsers.CompilationTimeStamp;
* @author Miklos Magyari
*
*/
public
interface
IFunctionBase
{
public
interface
IFunctionBase
{
/** checks whether two functions have the same signature */
IsIdenticalResult
isIdentical
(
CompilationTimeStamp
timestamp
,
IFunctionBase
other
);
/** Checks if a function is final (cannot be overridden) */
boolean
isFinal
();
/** Checks if a function is declared as abstract */
boolean
isAbstract
();
/** Gets the location of function signature (name and parameters) */
public
Location
getSignatureLocation
();
/** Gets the location of function signature (name and parameters) */
void
setSignatureLocation
(
Location
signatureLocation
);
}
org.eclipse.titan.designer/src/org/eclipse/titan/designer/AST/TTCN3/types/Class_Type.java
View file @
dee75b40
...
...
@@ -11,6 +11,7 @@ package org.eclipse.titan.designer.AST.TTCN3.types;
import
java.text.MessageFormat
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
org.eclipse.titan.designer.AST.ASTVisitor
;
import
org.eclipse.titan.designer.AST.Assignment
;
...
...
@@ -55,6 +56,7 @@ import org.eclipse.titan.designer.AST.TTCN3.definitions.VisibilityModifier;
import
org.eclipse.titan.designer.AST.TTCN3.statements.Assignment_Statement
;
import
org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock
;
import
org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template
;
import
org.eclipse.titan.designer.AST.TTCN3.templates.ParsedActualParameters
;
import
org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template
;
import
org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template
;
import
org.eclipse.titan.designer.AST.TTCN3.templates.TemplateInstance
;
...
...
@@ -112,10 +114,8 @@ public final class Class_Type extends Type implements ITypeWithComponents {
"public or protected methods `{0}''"
;
private
static
final
String
SHADOWSINHERITEDMEMBER
=
"`{0}'' shadows inherited member `{1}''"
;
private
static
final
String
SHADOWSINHERITED2
=
"`{0}'' shadows inherited {1} `{2}''"
;
private
static
final
String
TRAITNOCONSTRUCTOR
=
"Trait class type `{0}'' cannot have a constructor"
;
private
static
final
String
ABSTRACTCANNOTBEFINAL
=
"An absract class cannot be final"
;
private
static
final
String
TRAITCANNOTBEFINAL
=
"A trait class cannot be final"
;
private
static
final
String
ABSTRACTCANNOTBETRAIT
=
"A class cannot be both abstract and trait"
;
private
static
final
String
TRAITWITHFINALLY
=
"A trait class should not define a finally block"
;
private
static
final
String
UNKNOWNFIELD
=
"Unknown field reference"
;
private
static
final
String
PRIVATEINACCESSIBLE
=
"Private member is inaccessible due to its protection level"
;
...
...
@@ -143,11 +143,13 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private
Component_Type
mtcType
;
private
Component_Type
systemType
;
private
Identifier
classId
;
private
Types
baseTraits
;
private
Type
baseType
;
private
Definitions
members
;
private
Class_Type
baseClass
;
private
Def_Constructor
constructor
;
private
Map
<
FormalParameter
,
String
>
defaultParameterList
;
public
enum
ClassRelation
{
Identical
,
Related
,
Unrelated
...
...
@@ -576,11 +578,11 @@ public final class Class_Type extends Type implements ITypeWithComponents {
case
A_EXT_FUNCTION:
case
A_EXT_FUNCTION_RTEMP:
// currently all 'object' methods return a value, so these are erroneous by default
def
.
getLocation
().
reportSemanticError
(
((
IFunctionBase
)
def
)
.
get
Signature
Location
().
reportSemanticError
(
MessageFormat
.
format
(
DIFFERSFROMOBJECTMETHOD
,
def
.
getDescription
()));
break
;
default
:
def
.
getLocation
().
reportSemanticError
(
((
IFunctionBase
)
def
)
.
get
Signature
Location
().
reportSemanticError
(
MessageFormat
.
format
(
SHADOWSOBJECTMETHOD
,
def
.
getDescription
()));
nameClash
=
true
;
break
;
...
...
@@ -588,21 +590,41 @@ public final class Class_Type extends Type implements ITypeWithComponents {
}
}
if
(
isAbstract
&&
isFinal
)
{
modifierLocation
.
reportSemanticError
(
ABSTRACTCANNOTBEFINAL
);
setIsErroneous
(
true
);
}
if
(
isTrait
&&
isFinal
)
{
modifierLocation
.
reportSemanticError
(
TRAITCANNOTBEFINAL
);
setIsErroneous
(
true
);
if
(
constructor
!=
null
&&
isTrait
)
{
constructor
.
getLocation
().
reportSemanticError
(
MessageFormat
.
format
(
TRAITNOCONSTRUCTOR
,
getTypename
()));
}
if
(
isAbstract
&&
isTrait
)
{
modifierLocation
.
reportSemanticError
(
ABSTRACTCANNOTBETRAIT
);
setIsErroneous
(
true
);
if
(
constructor
==
null
&&
!
nameClash
&&
!
isTrait
)
{
// creating default constructor
Reference
baseCall
=
null
;
FormalParameterList
fpl
=
null
;
if
(!
isExternal
&&
baseClass
!=
null
)
{
Def_Constructor
baseConstructor
=
baseClass
.
getConstructor
(
timestamp
);
if
(
baseConstructor
!=
null
)
{
final
FormalParameterList
baseFpl
=
baseConstructor
.
getFormalParameterList
();
fpl
=
new
FormalParameterList
(
baseFpl
);
ParsedActualParameters
parsedApList
=
new
ParsedActualParameters
();
for
(
int
i
=
0
;
i
<
baseFpl
.
getNofParameters
();
i
++)
{
Reference
ref
=
new
Reference
(
null
,
baseFpl
.
getParameterByIndex
(
i
).
getIdentifier
().
newInstance
());
Referenced_Value
val
=
new
Referenced_Value
(
ref
);
SpecificValue_Template
temp
=
new
SpecificValue_Template
(
val
);
TemplateInstance
instance
=
new
TemplateInstance
(
null
,
null
,
temp
);
parsedApList
.
addUnnamedParameter
(
instance
);
// since the base constructor's formal parameters have already been checked
// (and their clones are also considered checked),
// the ones with default values need to be registered manually
FormalParameter
fp
=
fpl
.
getParameterByIndex
(
i
);
if
(
fp
.
hasDefaultValue
())
{
addDefaultParameter
(
fp
);
}
}
//baseCall = new Reference(baseClass.getMyScope().getParentScope().getModuleScope().getIdentifier().newInstance(),)
}
}
}
if
(
isTrait
&&
finallyBlock
!=
null
)
{
finallyBlock
.
getLocation
().
reportSemanticError
(
TRAITWITHFINALLY
);
setIsErroneous
(
true
);
...
...
@@ -706,6 +728,11 @@ public final class Class_Type extends Type implements ITypeWithComponents {
lastTimeChecked
=
timestamp
;
}
private
void
addDefaultParameter
(
FormalParameter
fp
)
{
final
String
name
=
classId
.
getName
()
+
"_defpar_type_"
+
defaultParameterList
.
size
();
defaultParameterList
.
put
(
fp
,
name
);
}
private
boolean
compareMembers
(
Class_Type
c1
,
Class_Type
c2
,
Location
subclassLoc
,
CompilationTimeStamp
timestamp
)
{
if
(
subclassLoc
!=
null
&&
(
c1
.
isParentClass
(
c2
,
timestamp
)
||
c2
.
isParentClass
(
c1
,
timestamp
)))
{
return
false
;
...
...
@@ -806,6 +833,14 @@ public final class Class_Type extends Type implements ITypeWithComponents {
return
nameClash
;
}
public
Class_Type
getScopeClass
()
{
final
Scope
parentScope
=
getMyScope
().
getParentScope
();
if
(
parentScope
!=
null
)
{
return
parentScope
.
getScopeClass
();
}
return
null
;
}
/**
* Gets the formal parameter list of default object methods
* @param methodName
...
...
@@ -825,6 +860,14 @@ public final class Class_Type extends Type implements ITypeWithComponents {
return
null
;
}
}
public
Def_Constructor
getConstructor
(
CompilationTimeStamp
timestamp
)
{
if
(
lastTimeChecked
!=
null
&&
!
lastTimeChecked
.
isLess
(
timestamp
))
{
check
(
timestamp
);
}
return
constructor
;
}
/**
* Gets the return type of default object methods
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment