Skip to content

Commit

Permalink
Merge branch 'master' into highprecision
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Jan 13, 2024
2 parents 6764185 + 583c449 commit b4e62d3
Show file tree
Hide file tree
Showing 14 changed files with 371 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
*
* Copyright (c) 2019 Nick Battle.
*
* Author: Nick Battle
*
* This file is part of VDMJ.
*
* VDMJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VDMJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
* SPDX-License-Identifier: GPL-3.0-or-later
*
******************************************************************************/

package annotations.ast;

import com.fujitsu.vdmj.ast.annotations.ASTAnnotation;
import com.fujitsu.vdmj.ast.lex.LexIdentifierToken;

public class ASTDocLinkAnnotation extends ASTAnnotation
{
private static final long serialVersionUID = 1L;

public ASTDocLinkAnnotation(LexIdentifierToken name)
{
super(name);
}
}
56 changes: 56 additions & 0 deletions annotations/src/main/java/annotations/in/INDocLinkAnnotation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*******************************************************************************
*
* Copyright (c) 2019 Nick Battle.
*
* Author: Nick Battle
*
* This file is part of VDMJ.
*
* VDMJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VDMJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
* SPDX-License-Identifier: GPL-3.0-or-later
*
******************************************************************************/

package annotations.in;

import com.fujitsu.vdmj.in.annotations.INAnnotation;
import com.fujitsu.vdmj.in.expressions.INExpression;
import com.fujitsu.vdmj.in.expressions.INExpressionList;
import com.fujitsu.vdmj.in.expressions.INStringLiteralExpression;
import com.fujitsu.vdmj.tc.lex.TCIdentifierToken;

public class INDocLinkAnnotation extends INAnnotation
{
private static final long serialVersionUID = 1L;

public INDocLinkAnnotation(TCIdentifierToken name, INExpressionList args)
{
super(name, args);
}

@Override
public String toString()
{
StringBuilder sb = new StringBuilder();

for (INExpression arg: args)
{
INStringLiteralExpression s = (INStringLiteralExpression) arg;
sb.append(s.value.value);
sb.append("\n");
}

return sb.toString();
}
}
13 changes: 12 additions & 1 deletion annotations/src/main/java/annotations/in/INOnFailAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package annotations.in;

import com.fujitsu.vdmj.in.annotations.INAnnotation;
import com.fujitsu.vdmj.in.annotations.INAnnotationList;
import com.fujitsu.vdmj.in.expressions.INExpression;
import com.fujitsu.vdmj.in.expressions.INExpressionList;
import com.fujitsu.vdmj.in.expressions.INIntegerLiteralExpression;
Expand All @@ -38,11 +39,13 @@ public class INOnFailAnnotation extends INAnnotation
{
private static final long serialVersionUID = 1L;
private final String format;
private final INAnnotationList doclinks; // INDocLinkAnnotations

public INOnFailAnnotation(TCIdentifierToken name, INExpressionList args, String format)
public INOnFailAnnotation(TCIdentifierToken name, INExpressionList args, String format, INAnnotationList doclinks)
{
super(name, args);
this.format = format;
this.doclinks = doclinks;
}

@Override
Expand Down Expand Up @@ -79,6 +82,14 @@ public void inAfter(INExpression exp, Value rv, Context ctxt)
}

Console.out.printf(errno + useformat + location + "\n", values);

if (doclinks != null)
{
for (INAnnotation link: doclinks)
{
Console.out.printf(link.toString());
}
}
}
}
catch (ValueException e)
Expand Down
144 changes: 144 additions & 0 deletions annotations/src/main/java/annotations/tc/TCDocLinkAnnotation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/*******************************************************************************
*
* Copyright (c) 2019 Nick Battle.
*
* Author: Nick Battle
*
* This file is part of VDMJ.
*
* VDMJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VDMJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
* SPDX-License-Identifier: GPL-3.0-or-later
*
******************************************************************************/

package annotations.tc;

import java.util.Stack;

import com.fujitsu.vdmj.tc.annotations.TCAnnotation;
import com.fujitsu.vdmj.tc.definitions.TCClassDefinition;
import com.fujitsu.vdmj.tc.definitions.TCDefinition;
import com.fujitsu.vdmj.tc.expressions.TCExpression;
import com.fujitsu.vdmj.tc.expressions.TCExpressionList;
import com.fujitsu.vdmj.tc.expressions.TCStringLiteralExpression;
import com.fujitsu.vdmj.tc.lex.TCIdentifierToken;
import com.fujitsu.vdmj.tc.modules.TCModule;
import com.fujitsu.vdmj.tc.statements.TCStatement;
import com.fujitsu.vdmj.tc.types.TCType;
import com.fujitsu.vdmj.typechecker.Environment;
import com.fujitsu.vdmj.typechecker.ModuleEnvironment;
import com.fujitsu.vdmj.typechecker.NameScope;
import com.fujitsu.vdmj.typechecker.PrivateClassEnvironment;

public class TCDocLinkAnnotation extends TCAnnotation
{
private static final long serialVersionUID = 1L;

private static Stack<TCDocLinkAnnotation> stack = new Stack<TCDocLinkAnnotation>();

public TCDocLinkAnnotation(TCIdentifierToken name, TCExpressionList args)
{
super(name, args);
}

@Override
public void tcBefore(TCModule module, ModuleEnvironment env)
{
stack.clear();
stack.push(this);
check();
}

@Override
public void tcBefore(TCClassDefinition clazz, PrivateClassEnvironment env)
{
stack.clear();
stack.push(this);
check();
}

@Override
public void tcBefore(TCDefinition def, Environment env, NameScope scope)
{
stack.push(this);
check();
}

@Override
public void tcBefore(TCStatement stmt, Environment env, NameScope scope)
{
stack.push(this);
check();
}

@Override
public void tcBefore(TCExpression exp, Environment env, NameScope scope)
{
stack.push(this);
check();
}

@Override
public void tcAfter(TCClassDefinition m, PrivateClassEnvironment env)
{
stack.pop();
}

@Override
public void tcAfter(TCModule m, ModuleEnvironment e)
{
stack.pop();
}

@Override
public void tcAfter(TCDefinition def, TCType type, Environment env, NameScope scope)
{
stack.pop();
}

@Override
public void tcAfter(TCExpression exp, TCType type, Environment env, NameScope scope)
{
stack.pop();
}

@Override
public void tcAfter(TCStatement stmt, TCType type, Environment env, NameScope scope)
{
stack.pop();
}

public void check()
{
if (args.isEmpty())
{
name.report(6008, "@DocLink(\"arg\"...)");
}
else
{
for (TCExpression arg: args)
{
if (!(arg instanceof TCStringLiteralExpression))
{
arg.report(6008, "@DocLink args must be string literals");
}
}
}
}

public static Stack<TCDocLinkAnnotation> enclosing()
{
return stack;
}
}
12 changes: 12 additions & 0 deletions annotations/src/main/java/annotations/tc/TCOnFailAnnotation.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
package annotations.tc;

import java.util.Arrays;
import java.util.Stack;

import com.fujitsu.vdmj.tc.annotations.TCAnnotation;
import com.fujitsu.vdmj.tc.annotations.TCAnnotationList;
import com.fujitsu.vdmj.tc.definitions.TCClassDefinition;
import com.fujitsu.vdmj.tc.definitions.TCDefinition;
import com.fujitsu.vdmj.tc.expressions.TCExpression;
Expand All @@ -46,6 +48,8 @@ public class TCOnFailAnnotation extends TCAnnotation
{
private static final long serialVersionUID = 1L;
private String format = null;
@SuppressWarnings("unused")
private TCAnnotationList doclinks = null;

public TCOnFailAnnotation(TCIdentifierToken name, TCExpressionList args)
{
Expand Down Expand Up @@ -129,6 +133,14 @@ public void tcBefore(TCExpression exp, Environment env, NameScope scope)
{
name.report(6008, "@OnFail must only use %[arg$][#][width]s conversions");
}

Stack<TCDocLinkAnnotation> enclosing = TCDocLinkAnnotation.enclosing();

if (!enclosing.isEmpty())
{
doclinks = new TCAnnotationList();
doclinks.addAll(enclosing);
}
}
else
{
Expand Down
Loading

0 comments on commit b4e62d3

Please sign in to comment.