Commit fc48ff00 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

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


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 88dc9364
......@@ -23,6 +23,7 @@ import org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute;
import org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Modifier_type;
import org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath;
import org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template;
import org.eclipse.titan.designer.AST.TTCN3.types.Class_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.subtypes.ParsedSubType;
import org.eclipse.titan.designer.AST.TTCN3.types.subtypes.SubType;
import org.eclipse.titan.designer.AST.TTCN3.values.Expression_Value.Operation_type;
......@@ -1531,4 +1532,11 @@ public interface IType extends IGovernor, IIdentifierContainer, IVisitableNode,
* @return the JSON type of the type
*/
public int getJsonValueType();
public default Class_Type getClassTypeBody() {
if (getTypetype() != Type_type.TYPE_CLASS) {
// fatal error
}
return (Class_Type)this;
}
}
......@@ -22,6 +22,7 @@ import org.eclipse.titan.designer.AST.TTCN3.definitions.PortScope;
import org.eclipse.titan.designer.AST.TTCN3.definitions.RunsOnScope;
import org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock;
import org.eclipse.titan.designer.AST.TTCN3.types.Altstep_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.Class_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.Component_Type;
import org.eclipse.titan.designer.AST.TTCN3.types.Function_Type;
import org.eclipse.titan.designer.editors.ProposalCollector;
......@@ -34,6 +35,7 @@ import org.eclipse.ui.IEditorPart;
* The Scope class represents general visibility scopes.
*
* @author Kristof Szabados
* @author Miklos Magyari
* */
public abstract class Scope implements INamedNode, IIdentifierContainer, IVisitableNode, ICommentable {
private static final String RUNSONREQUIRED = "A definition without `runs on'' clause cannot {0} {1}, which runs on component type `{2}''";
......@@ -806,4 +808,11 @@ public abstract class Scope implements INamedNode, IIdentifierContainer, IVisita
// Do nothing
return null;
}
public Class_Type getScopeClass() {
if (parentScope != null) {
return parentScope.getScopeClass();
}
return null;
}
}
......@@ -34,7 +34,9 @@ public final class Types extends ASTNode {
}
public synchronized Type extractTypeByIndex(final int index) {
return types.remove(index);
final Type type = types.get(index);
types.set(index, null);
return type;
}
public int getNofTypes() {
......
/******************************************************************************
* 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.Type;
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;
/**
* This class represents abstract functions used in Ttcn3 classes
*
* @author Miklos Magyari
*/
public class Def_AbsFunction extends Definition implements IParameterisedAssignment {
private Type returnType;
protected Def_AbsFunction(Identifier identifier) {
super(identifier);
// TODO Auto-generated constructor stub
}
@Override
public String getOutlineIcon() {
if (returnType == null) {
return "function.gif";
}
return "function_return.gif";
}
@Override
public FormalParameterList getFormalParameterList() {
// TODO Auto-generated method stub
return null;
}
@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
}
}
......@@ -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
public void checkUniqueness(final CompilationTimeStamp timestamp) {
protected void checkUniqueness(final CompilationTimeStamp timestamp) {
if (lastUniquenessCheckTimeStamp != null && !lastUniquenessCheckTimeStamp.isLess(timestamp)) {
return;
}
......
......@@ -91,6 +91,9 @@ public final class Class_Type extends Type implements ITypeWithComponents {
"(`{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 SHADOWSRUNSON = "`{0}'' shadows a definition in runs-on component type `{1}''";
private static final String SHADOWSMTC = "`{0}'' shadows a definition in mtc component type `{1}''";
private static final String SHADOWSSYSTEM = "`{0}'' shadows a definition in system component type `{1}''";
private static final String ABSTRACTCANNOTBEFINAL = "An absract class cannot be final";
private static final String TRAITCANNOTBEFINAL = "A trait class cannot be final";
......@@ -218,6 +221,9 @@ public final class Class_Type extends Type implements ITypeWithComponents {
if (baseTraits != null) {
baseTraits.setMyScope(scope);
}
if (members != null) {
members.setParentScope(scope);
}
}
@Override
......@@ -326,7 +332,7 @@ public final class Class_Type extends Type implements ITypeWithComponents {
}
baseTraits.extractTypeByIndex(i);
} else {
final Class_Type tClass = (Class_Type)t.getTypeRefdLast(timestamp);
final Class_Type tClass = t.getTypeRefdLast(timestamp).getClassTypeBody();
if (! tClass.isTrait) {
if (isTrait) {
t.getLocation().reportSemanticError(TRAITEXTENDTRAIT);
......@@ -453,8 +459,8 @@ public final class Class_Type extends Type implements ITypeWithComponents {
}
}
members.checkUniqueness(timestamp);
//members.check(timestamp);
// uniqueness is checked by check()
members.check(timestamp);
for (int i = 0; i < members.getNofAssignments(); i++) {
final Assignment ass = members.getAssignmentByIndex(i);
......@@ -472,6 +478,30 @@ public final class Class_Type extends Type implements ITypeWithComponents {
}
}
if (runsOnType != null | mtcType != null | systemType != null) {
for (int i = 0; i < members.getNofAssignments(); i++) {
final Assignment localDef = members.getAssignmentByIndex(i);
final Identifier localId = localDef.getIdentifier();
if (runsOnType != null && runsOnType.getComponentBody().hasLocalAssignmentWithId(localId)) {
localDef.getLocation().reportSemanticError(
MessageFormat.format(SHADOWSRUNSON, localDef.getDescription(), runsOnType.getTypename()));
}
if (mtcType != null && mtcType.getComponentBody().hasLocalAssignmentWithId(localId)) {
localDef.getLocation().reportSemanticError(
MessageFormat.format(SHADOWSMTC, localDef.getDescription(), mtcType.getTypename()));
}
if (systemType != null && systemType.getComponentBody().hasLocalAssignmentWithId(localId)) {
localDef.getLocation().reportSemanticError(
MessageFormat.format(SHADOWSSYSTEM, localDef.getDescription(), systemType.getTypename()));
}
}
}
boolean nameClash = false;
if (baseClass != null) {
nameClash = compareMembers(this, baseClass, null, timestamp);
}
if (isAbstract && isFinal) {
modifierLocation.reportSemanticError(ABSTRACTCANNOTBEFINAL);
setIsErroneous(true);
......@@ -590,6 +620,130 @@ public final class Class_Type extends Type implements ITypeWithComponents {
lastTimeChecked = timestamp;
}
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;
}
boolean nameClash = false;
for (int i = 0; i < c1.members.getNofAssignments(); i++) {
final Assignment def1 = c1.members.getAssignmentByIndex(i);
if (def1.getAssignmentType() == Assignment_type.A_CONSTRUCTOR) {
continue;
}
final Identifier id1 = def1.getIdentifier();
if (c2.hasLocalAssignemtWithID(id1, timestamp)) {
final Assignment def2 = c2.getLocalAssignmentByID(id1, timestamp);
Class_Type def2Class = def2.getMyScope().getScopeClass();
if (subclassLoc != null && def2Class != c2 && def2Class != c1 && c1.isParentClass(def2Class, timestamp)) {
continue;
}
switch(def1.getAssignmentType()) {
case A_FUNCTION:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION:
case A_EXT_FUNCTION_RVAL:
case A_EXT_FUNCTION_RTEMP:
switch(def2.getAssignmentType()) {
case A_FUNCTION:
case A_FUNCTION_RVAL:
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION:
case A_EXT_FUNCTION_RVAL:
case A_EXT_FUNCTION_RTEMP:
Def_Function func1 = (Def_Function)def1;
Def_Function func2 = (Def_Function)def2;
break;
default:
break;
}
break;
default:
break;
}
}
}
return nameClash;
}
private boolean isParentClass(final Class_Type pclass, CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
check(timestamp);
}
if (this == pclass || (! isTrait && pclass.isBuiltIn)) {
return true;
}
if (baseClass != null && baseClass.isParentClass(pclass, timestamp)) {
return true;
}
if (baseTraits != null) {
for (int i = 0; i < baseTraits.getNofTypes(); i++) {
final Type baseTrait = baseTraits.getType(i);
if (baseTrait != null &&
baseTrait.getTypeRefdLast(timestamp).getClassTypeBody().isParentClass(pclass, timestamp)) {
return true;
}
}
}
return false;
}
private boolean hasLocalAssignemtWithID(final Identifier id, CompilationTimeStamp timestamp) {
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
check(timestamp);
}
if (isBuiltIn) {
return false;
}
if (members.hasLocalAssignmentWithID(timestamp, id)) {
return true;
}
if (baseClass != null && baseClass.hasLocalAssignemtWithID(id, timestamp)) {
return true;
}
if (baseTraits != null) {
for (int i = 0; i < baseTraits.getNofTypes(); i++) {
final Type baseTrait = baseTraits.getType(i);
if (baseTrait != null &&
baseTrait.getTypeRefdLast(timestamp).getClassTypeBody().hasLocalAssignemtWithID(id, timestamp)) {
return true;
}
}
}
return false;
}
private Assignment getLocalAssignmentByID(final Identifier id, CompilationTimeStamp timestamp) {
if (isBuiltIn) {
// TODO fatal
}
if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
check(timestamp);
}
Assignment ass = null;
if (members.hasLocalAssignmentWithID(timestamp, id)) {
ass = members.getLocalAssignmentByID(timestamp, id);
}
if (ass == null && baseClass != null) {
ass = baseClass.getLocalAssignmentByID(id, timestamp);
}
if (ass == null && baseTraits != null) {
for (int i = 0; i < baseTraits.getNofTypes(); i++) {
final Type baseTrait = baseTraits.getType(i);
if (baseTrait != null) {
ass = baseTrait.getTypeRefdLast(timestamp).getClassTypeBody().getLocalAssignmentByID(id, timestamp);
if (ass != null) {
break;
}
}
}
}
return ass;
}
@Override
/** {@inheritDoc} */
public void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
......
......@@ -9446,7 +9446,10 @@ pr_BaseClassList returns[Types baseTypes]
(
COMMA
(
rt2 = pr_Type { $baseTypes.addType($rt2.type); }
rt2 = pr_ReferencedType {
$rt2.type.setLocation(getLocation($rt2.start, $rt2.stop));
$baseTypes.addType($rt2.type);
}
| OBJECTKEYWORD { $baseTypes.addType(new Class_Type()); }
)
)*
......
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