Commit 617bf833 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Implemented signatureLocation for class methods


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 750ca23f
......@@ -160,6 +160,14 @@ public final class Def_Function extends Definition implements IParameterisedAssi
private final Location classModifierLocation;
private final Location funcModifierLocation;
/** Location of the function's signature (from 'function' keyword up to the return value)
* Used when we want to report errors/warnings for a whole function but underlining the
* entire definition (including the body and finally block) looks ugly
*
* Right now, only used for class methods.
*/
private Location signatureLocation = null;
private boolean isConstructor = false;
/** Indicates if this function is a class function overriding a function of the parent class */
......@@ -1616,4 +1624,12 @@ public final class Def_Function extends Definition implements IParameterisedAssi
public void setOverride(boolean isOverride) {
this.isOverride = isOverride;
}
public Location getSignatureLocation() {
return signatureLocation;
}
public void setSignatureLocation(Location signatureLocation) {
this.signatureLocation = signatureLocation;
}
}
......@@ -57,7 +57,7 @@ public class DefinitionContainer implements Iterable<Definition> {
func.getType(timestamp).isIdentical(timestamp, ClassTypeBody.getObjectMethodReturnType(name)) &&
! func.isAbstract()) {
if (inres == IsIdenticalResult.RES_NAME_DIFFERS) {
funclist.getLocation().reportSemanticWarning(FormalParameterList.ONEORMORENAMESDIFER);
func.getSignatureLocation().reportSemanticWarning(FormalParameterList.ONEORMORENAMESDIFER);
}
break;
}
......@@ -67,9 +67,12 @@ public class DefinitionContainer implements Iterable<Definition> {
case A_FUNCTION_RTEMP:
case A_EXT_FUNCTION:
case A_EXT_FUNCTION_RTEMP:
def.getIdentifier().getLocation().reportSemanticError(MessageFormat.format(
"The prototype of method `{0}' is not identical to that of the method inherited from the 'object' class",
def.getIdentifier().getName()));
if (def instanceof Def_Function) {
final Def_Function func = (Def_Function)def;
func.getSignatureLocation().reportSemanticError(MessageFormat.format(
"The prototype of method `{0}' is not identical to that of the method inherited from the 'object' class",
def.getIdentifier().getName()));
}
break;
default:
def.getIdentifier().getLocation().reportSemanticError(MessageFormat.format(
......
......@@ -9550,10 +9550,12 @@ pr_ClassFunctionDef returns[Def_Function def_func]
boolean isDeterministic = false;
Location modifierLocation = null;
SignatureExceptions exceptions = null;
Token startcol = null;
Token endcol = null;
}:
(
pr_ExtKeyword?
col = pr_FunctionKeyword
col = pr_FunctionKeyword { startcol = $col.start; }
cfm = pr_ClassFunctionModifier {
isFinal = $cfm.isFinal;
isAbstract = $cfm.isAbstract;
......@@ -9563,20 +9565,21 @@ pr_ClassFunctionDef returns[Def_Function def_func]
id = pr_Identifier
start1 = pr_LParen
(pl = pr_FunctionFormalParList { parameters = $pl.parList; } )?
end = pr_RParen
end = pr_RParen { endcol = $end.stop; }
( runs = pr_RunsOnSpec[runsonHelper] { runsonHelper.runsonReference.setLocation(getLocation($runs.start, $runs.stop)); })?
mtc = pr_AltOrTcConfigSpec[ runsonHelper ] {
if (runsonHelper.mtcReference != null) runsonHelper.mtcReference.setLocation(getLocation($mtc.start, $mtc.stop));
if (runsonHelper.systemReference != null) runsonHelper.systemReference.setLocation(getLocation($mtc.start, $mtc.stop));
}
( rh = pr_ReturnType
{ returnHelper = $rh.helper;
if(returnHelper != null) {
returnType = returnHelper.type;
returnsTemplate = returnHelper.returnsTemplate;
templateRestriction = returnHelper.templateRestriction;
}
( rh = pr_ReturnType {
endcol = $rh.stop;
returnHelper = $rh.helper;
if(returnHelper != null) {
returnType = returnHelper.type;
returnsTemplate = returnHelper.returnsTemplate;
templateRestriction = returnHelper.templateRestriction;
}
}
)?
( exc = pr_ExceptionSpec { exceptions = $exc.exceptions; } )?
( sb=pr_StatementBlock { statementBlock = $sb.statementblock; })?
......@@ -9587,6 +9590,7 @@ pr_ClassFunctionDef returns[Def_Function def_func]
parameters.setLocation(getLocation( $start1.start, $end.stop));
$def_func = new Def_Function($id.identifier, parameters, runsonHelper.runsonReference, runsonHelper.mtcReference, runsonHelper.systemReference,
portReference, returnType, returnsTemplate, templateRestriction, exceptions, statementBlock, null, true, isAbstract, isFinal, modifierLocation, false, false, null);
$def_func.setSignatureLocation(getLocation(startcol, endcol));
$def_func.setLocation(getLocation( $col.start, $sb.stop));
}
};
......
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