Commit 88dc9364 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: synch with titan core (2) (issue #487)


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 3debb528
......@@ -12,6 +12,7 @@ import org.eclipse.titan.designer.AST.ASN1.definitions.SpecialASN1Module;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter.parameterEvaluationType;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Group;
import org.eclipse.titan.designer.AST.TTCN3.definitions.VisibilityModifier;
import org.eclipse.titan.designer.compiler.JavaGenData;
import org.eclipse.titan.designer.declarationsearch.Declaration;
import org.eclipse.titan.designer.editors.AstSyntaxHighlightTokens;
......@@ -50,6 +51,7 @@ public abstract class Assignment extends ASTNode implements IOutlineElement, ILo
/** template variable, dynamic template (TTCN-3). */ A_VAR_TEMPLATE,
/** timer (TTCN-3). */ A_TIMER,
/** testcase (TTCN-3). */ A_TESTCASE,
/** constructor (TTCN-3 oop extension) */ A_CONSTRUCTOR,
/** formal parameter (value) (TTCN3). */ A_PAR_VAL,
/** formal parameter (in value) (TTCN3). */ A_PAR_VAL_IN,
/** formal parameter (out value) (TTCN3). */ A_PAR_VAL_OUT,
......@@ -100,6 +102,8 @@ public abstract class Assignment extends ASTNode implements IOutlineElement, ILo
/** used by the incremental processing to signal if the assignment can be the root of a change */
private boolean canBeCheckRoot = true;
protected VisibilityModifier visibility;
public Assignment(final Identifier identifier) {
this.identifier = identifier;
isErroneous = false;
......@@ -329,6 +333,10 @@ public abstract class Assignment extends ASTNode implements IOutlineElement, ILo
public Declaration getDeclaration() {
return Declaration.createInstance(this);
}
public VisibilityModifier getVisibility() {
return visibility;
}
/**
* Returns a string containing the Java reference pointing to this
......
/******************************************************************************
* Copyright (c) 2000-2022 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
******************************************************************************/
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.Reference;
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 {
private final StatementBlock statementBlock;
public Def_Constructor(FormalParameterList fpl, Reference baseCall, StatementBlock sb) {
super(new Identifier(Identifier_type.ID_TTCN, "create"));
statementBlock = sb;
}
@Override
public String getOutlineIcon() {
return "function.gif";
}
@Override
public String getProposalKind() {
// TODO Auto-generated method stub
return null;
}
@Override
public void updateSyntax(TTCN3ReparseUpdater reparser, boolean isDamaged) throws ReParseException {
// TODO Auto-generated method stub
}
@Override
public Assignment_type getAssignmentType() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getAssignmentName() {
// TODO Auto-generated method stub
return null;
}
@Override
public void check(CompilationTimeStamp timestamp) {
// TODO Auto-generated method stub
}
@Override
public void check(CompilationTimeStamp timestamp, IReferenceChain refChain) {
// TODO Auto-generated method stub
}
@Override
public void generateCode(JavaGenData aData, boolean cleanUp) {
// TODO Auto-generated method stub
}
}
......@@ -192,7 +192,7 @@ public final class Definitions extends Assignments implements ILocateableNode {
* @param definitionList
* the definitions to be added
* */
public void addDefinitions(final List<Definition> definitionList) {
public synchronized void addDefinitions(final List<Definition> definitionList) {
lastUniquenessCheckTimeStamp = null;
if (definitionList != null) {
final ArrayList<Definition> safeToAdd = new ArrayList<Definition>(definitionList.size());
......@@ -232,7 +232,7 @@ public final class Definitions extends Assignments implements ILocateableNode {
* */
//checkUniquiness has been splitted into to parts because
//the check should be done at the beginning of the check but the reporting shall be done finally
protected void checkUniqueness(final CompilationTimeStamp timestamp) {
public void checkUniqueness(final CompilationTimeStamp timestamp) {
if (lastUniquenessCheckTimeStamp != null && !lastUniquenessCheckTimeStamp.isLess(timestamp)) {
return;
}
......
......@@ -38,11 +38,13 @@ import org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type;
import org.eclipse.titan.designer.AST.TTCN3.TemplateRestriction.Restriction_type;
import org.eclipse.titan.designer.AST.TTCN3.attributes.Types;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Const;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Constructor;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Function;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Template;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Var_Template;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definition;
import org.eclipse.titan.designer.AST.TTCN3.definitions.Definitions;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameter;
import org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList;
import org.eclipse.titan.designer.AST.TTCN3.definitions.VisibilityModifier;
......@@ -76,6 +78,19 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private static final String RUNSONINCOMPATIBLE = "The `runs on' component type of the subclass, `{0}'', is not compatible with the `runs on' component type of the superclass, `{1}''";
private static final String MTCINCOMPATIBLE = "The `mtc' component type of the subclass, `{0}'', is not compatible with the `runs on' component type of the superclass, `{1}''";
private static final String SYSTEMINCOMPATIBLE = "The `system' component type of the subclass, `{0}'', is not compatible with the `runs on' component type of the superclass, `{1}''";
private static final String SUBCLASSHASNORUNSON = "Supertrait `{0}'' has a `runs on` component type, but the subclass and its superclass does not";
private static final String SUBCLASSHASNOMTC = "Supertrait `{0}'' has an `mtc` component type, but the subclass and its superclass does not";
private static final String SUBCLASSHASNOSYSTEM = "Supertrait `{0}'' has a `system` component type, but the subclass and its superclass does not";
private static final String RUNSONINCOMPATIBLETRAIT = "The `runs on' component type of the subclass " +
"(`{0}'') is not compatible with the `mtc' component type of " +
"supertrait `{1}'' (`{2}'')";
private static final String MTCINCOMPATIBLETRAIT = "The `runs on' component type of the subclass " +
"(`{0}'') is not compatible with the `mtc' component type of " +
"supertrait `{1}'' (`{2}'')";
private static final String SYSTEMINCOMPATIBLETRAIT = "The `system' component type of the subclass " +
"(`{0}'') is not compatible with the `system' component type of " +
"supertrait `{1}'' (`{2}'')";
private static final String MEMBERCANNOTBEPUBLIC = "Class members cannot be public";
private static final String ABSTRACTCANNOTBEFINAL = "An absract class cannot be final";
private static final String TRAITCANNOTBEFINAL = "A trait class cannot be final";
......@@ -102,7 +117,6 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private final Reference runsOnRef;
private final Reference mtcRef;
private final Reference systemRef;
private final ClassTypeReferenceList refs;
private Component_Type runsOnType;
private Component_Type mtcType;
......@@ -110,7 +124,9 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private Types baseTraits;
private Type baseType;
private Definitions members;
private Class_Type baseClass;
private Def_Constructor constructor;
public enum ClassRelation {
Identical, Related, Unrelated
......@@ -118,7 +134,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
public Class_Type(ClassTypeBody classBody, boolean isAbstract, boolean isFinal, boolean isTrait, boolean isExternal,
Location modifierLocation, final Reference runsOnRef, final Reference mtcRef, final Reference systemRef,
ClassTypeReferenceList refs, Types baseTraits, StatementBlock finallyBlock) {
Definitions members, Types baseTraits, StatementBlock finallyBlock) {
this.classBody = classBody;
this.isAbstract = isAbstract;
......@@ -130,7 +146,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
this.runsOnRef = runsOnRef;
this.mtcRef = mtcRef;
this.systemRef = systemRef;
this.refs = refs;
this.members = members;
this.baseTraits = baseTraits;
if (classBody != null) {
......@@ -290,7 +306,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
return;
}
if (isBuiltIn) {
if (isBuiltIn) {
return;
}
if ((isFinal && isAbstract) || (isFinal && isTrait) || (isAbstract && isTrait)) {
......@@ -385,6 +401,77 @@ public final class Class_Type extends Type implements ITypeWithComponents {
systemType = baseClass.getSystemType(timestamp);
}
if (baseTraits != null) {
for (int i = 0; i < baseTraits.getNofTypes(); i++) {
final Type baseTrait = baseTraits.getType(i);
if (baseTrait != null) {
final Class_Type baseTraitClass = (Class_Type)baseTrait.getTypeRefdLast(timestamp);
final Component_Type baseRunsOnType = baseTraitClass.getRunsOnType(timestamp);
if (baseRunsOnType != null) {
if (runsOnType == null) {
getLocation().reportSemanticError(
MessageFormat.format(SUBCLASSHASNORUNSON, baseTraitClass.getFullName()));
} else if (!baseRunsOnType.isCompatible(timestamp, runsOnType, null, null, null) ) {
runsOnRef.getLocation().reportSemanticError(
MessageFormat.format(RUNSONINCOMPATIBLETRAIT, runsOnType.getTypename(),
baseTraitClass.getIdentifier().getDisplayName(),
baseRunsOnType.getTypename()));
}
}
final Component_Type baseMtcType = baseTraitClass.getMtcType(timestamp);
if (baseMtcType != null) {
if (mtcType == null) {
getLocation().reportSemanticError(
MessageFormat.format(SUBCLASSHASNOMTC, baseTraitClass.getFullName()));
} else if (!baseMtcType.isCompatible(timestamp, mtcType, null, null, null) ) {
mtcRef.getLocation().reportSemanticError(
MessageFormat.format(MTCINCOMPATIBLETRAIT, mtcType.getTypename(),
baseTraitClass.getIdentifier().getDisplayName(),
baseMtcType.getTypename()));
}
}
final Component_Type baseSystemType = baseTraitClass.getSystemType(timestamp);
if (baseSystemType != null) {
if (systemType == null) {
getLocation().reportSemanticError(
MessageFormat.format(SUBCLASSHASNOSYSTEM, baseTraitClass.getFullName()));
} else if (!baseSystemType.isCompatible(timestamp, systemType, null, null, null) ) {
systemRef.getLocation().reportSemanticError(
MessageFormat.format(SYSTEMINCOMPATIBLETRAIT, systemType.getTypename(),
baseTraitClass.getIdentifier().getDisplayName(),
baseSystemType.getTypename()));
}
}
}
}
}
for (int i = 0; i < members.getNofAssignments(); i++) {
final Assignment ass = members.getAssignmentByIndex(i);
if (ass.getAssignmentType() == Assignment_type.A_CONSTRUCTOR) {
constructor = (Def_Constructor)ass;
}
}
members.checkUniqueness(timestamp);
//members.check(timestamp);
for (int i = 0; i < members.getNofAssignments(); i++) {
final Assignment ass = members.getAssignmentByIndex(i);
switch(ass.getAssignmentType()) {
case A_CONST:
case A_VAR:
case A_TEMPLATE:
case A_VAR_TEMPLATE:
if (ass.getVisibility() == VisibilityModifier.Public) {
ass.getLocation().reportSemanticError(MEMBERCANNOTBEPUBLIC);
}
break;
default:
break;
}
}
if (isAbstract && isFinal) {
modifierLocation.reportSemanticError(ABSTRACTCANNOTBEFINAL);
setIsErroneous(true);
......
......@@ -9328,6 +9328,7 @@ pr_ClassTypeDef returns[Def_Type def_type]
Configuration_Helper systemspecHelper = new Configuration_Helper();
ClassTypeBody body = null;
ClassTypeReferenceList refs = null;
Definitions definitions = null;
Types types = null;
VisibilityModifier visibility = VisibilityModifier.Protected;
Location modifierLocation = null;
......@@ -9347,8 +9348,8 @@ pr_ClassTypeDef returns[Def_Type def_type]
}
i = pr_Identifier
ecd = pr_ExtendsClassDef {
refs = $ecd.refList;
refs.setLocation(getLocation( $ecd.start, $ecd.stop ));
// refs = $ecd.refList;
// refs.setLocation(getLocation( $ecd.start, $ecd.stop ));
types = $ecd.baseTypes;
}
(runson = pr_RunsOnSpec[runsonHelper] {
......@@ -9369,6 +9370,7 @@ pr_ClassTypeDef returns[Def_Type def_type]
pr_BeginChar
cml = pr_ClassMemberList[$i.identifier, refs] {
body = $cml.body;
definitions = $cml.definitions;
body.setLocation(getLocation( $cml.start, $cml.stop ));
}
pr_EndChar
......@@ -9379,13 +9381,12 @@ pr_ClassTypeDef returns[Def_Type def_type]
{
if ($i.identifier != null) {
if (body == null) {
body = new ClassTypeBody($i.identifier, refs);
body = new ClassTypeBody($i.identifier, null);
}
Class_Type type = new Class_Type(body, isAbstract, isFinal, isTrait, isExternal, modifierLocation, runsonHelper.runsonReference, mtcHelper.mtcReference, systemspecHelper.systemReference, refs, types, finallyBlock);
Class_Type type = new Class_Type(body, isAbstract, isFinal, isTrait, isExternal, modifierLocation, runsonHelper.runsonReference, mtcHelper.mtcReference, systemspecHelper.systemReference, definitions, types, finallyBlock);
type.setLocation(getLocation($start, getLastVisibleToken()));
$def_type = new Def_Type($i.identifier, type);
$def_type.setLocation(getLocation($kw.start, $i.stop));
refs.setParentClass(type);
}
};
......@@ -9429,25 +9430,6 @@ pr_ExtendsClassDef returns[ClassTypeReferenceList refList, Types baseTypes]
(
EXTENDS
bcl = pr_BaseClassList { $baseTypes = $bcl.baseTypes; }
// ( ec = pr_ExtendsClassItem {
// if ($ec.reference != null) {
// $refList.addReference($ec.reference);
// }
// Class_Type type = new Class_Type();
// type.setLocation(getLocation($ec.start, $ec.stop));
// $baseTypes.addType(type);
// }
// | OBJECTKEYWORD { } // left empty on purpose
// )
// ( COMMA ec2 = pr_ExtendsClassItem {
// if ($ec2.reference != null) {
// $refList.addReference($ec2.reference);
// }
// Class_Type type = new Class_Type();
// type.setLocation(getLocation($ec.start, $ec.stop));
// $baseTypes.addType(type);
// }
// )*
)?;
pr_BaseClassList returns[Types baseTypes]
......@@ -9485,12 +9467,15 @@ pr_ExtendsClassItem returns[Reference reference]
};
pr_ClassMemberList [Identifier identifier, ClassTypeReferenceList refs]
returns[ClassTypeBody body]
returns[ClassTypeBody body, Definitions definitions]
@init {
$body = new ClassTypeBody( $identifier, $refs );
$definitions = new Definitions();
}:
(
cm = pr_ClassMember { if ($cm.definitions != null) { $body.addAssignments( $cm.definitions ); } }
cm = pr_ClassMember { if ($cm.definitions != null) {
$definitions.addDefinitions( $cm.definitions );
} }
pr_WithStatement? SEMICOLON?
)*
;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment