Commit 44f1fa1f authored by earplov's avatar earplov
Browse files

LocationAST dependency removed from cfg section handlers and cfg editor pages


Signed-off-by: default avatarearplov <arpad.lovassy@ericsson.com>
parent ce3d9b93
......@@ -14,8 +14,12 @@ import org.antlr.v4.runtime.tree.ParseTreeVisitor;
*/
public class AddedParseTree implements ParseTree {
/** text of the parse tree node. It doesn't have to be 1 token, it can be any string. */
private String mText;
/** parent rule */
private ParseTree mParent;
public AddedParseTree( final String aText ) {
mText = aText;
}
......@@ -52,7 +56,7 @@ public class AddedParseTree implements ParseTree {
@Override
public ParseTree getParent() {
return null;
return mParent;
}
@Override
......@@ -68,5 +72,10 @@ public class AddedParseTree implements ParseTree {
public void setText(String aText) {
mText = aText;
}
public void setParent( final ParseTree aParent ) {
mParent = aParent;
}
}
/******************************************************************************
* Copyright (c) 2000-2015 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
package org.eclipse.titan.common.parsers;
public class CommonHiddenStreamToken {
private String mText;
private CommonHiddenStreamToken mHiddenBefore;
private CommonHiddenStreamToken mHiddenAfter;
public CommonHiddenStreamToken(final String aText) {
mText = aText;
}
public String getText() {
return mText;
}
public CommonHiddenStreamToken getHiddenBefore() {
return mHiddenBefore;
}
public CommonHiddenStreamToken getHiddenAfter() {
return mHiddenAfter;
}
}
/******************************************************************************
* Copyright (c) 2000-2015 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
package org.eclipse.titan.common.parsers;
/**
* This interface merely serves for us as a common point between the different LocationAST used by the different parsers. So that we can report
* problems on a common base.
*
* @author Kristof Szabados
* */
public interface ILocationAST {
/**
* @return the offset at the beginning of the represented element.
* */
int getOffset();
/**
* Sets the offset for the beginning of the represented element.
*
* @param offset the offset to set
* */
void setOffset(int offset);
/**
* @return the offset at the end of the represented element.
* */
int getEndOffset();
/**
* Sets the offset for the end of the represented element.
*
* @param endOffset the offset to set
* */
void setEndOffset(int endOffset);
/**
* @return the line in which the beginning of the represented element started
* */
int getLine();
}
/******************************************************************************
* Copyright (c) 2000-2015 Ericsson Telecom AB
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
******************************************************************************/
package org.eclipse.titan.common.parsers;
import java.util.ArrayList;
import java.util.List;
import org.antlr.v4.runtime.CommonToken;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
//TODO: rename to CfgParseTree, inherit from ParserRuleContext
/**
* @author Kristof Szabados
* @author Arpad Lovassy
*/
public class LocationAST {
private TokenStream mTokenStream;
private ParserRuleContext mRule;
private CommonHiddenStreamToken mHiddenAfter;
private CommonHiddenStreamToken mHiddenBefore;
public LocationAST( final String aText ) {
setText( aText );
}
public LocationAST( final ParserRuleContext aRule, TokenStream aTokenStream ) {
setRule( aRule );
mTokenStream = aTokenStream;
}
public LocationAST( final ParserRuleContext aRule ) {
setRule( aRule );
}
public LocationAST( final Token aToken ) {
setToken( aToken );
}
private void setToken( Token aToken ) {
ParserRuleContext rule = new ParserRuleContext();
rule.addChild( aToken );
setRule( rule );
}
private void setRule( ParserRuleContext aRule ) {
mRule = aRule;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("{ ");
if ( mRule != null ) {
sb.append("{ " + mRule.start + ", ");
sb.append("" + mRule.stop + ", ");
sb.append("" + mRule.getChildCount() + ", " );
sb.append(mRule.getText() + "}" );
} else {
sb.append("null");
}
sb.append(", " );
sb.append(mHiddenAfter+", ");
sb.append(mHiddenBefore+"}");
return sb.toString();
}
public String getText() {
String text = mRule != null ? mRule.getText() : null;
return text;
}
public void setText( final String aText ) {
CommonToken token = new CommonToken( 0, aText );
setToken( token );
}
public ParserRuleContext getRule() {
return mRule;
}
public LocationAST getParent() {
final ParserRuleContext parentRule = mRule != null ? mRule.getParent() : null;
return new LocationAST( parentRule, mTokenStream );
}
public LocationAST getFirstChild() {
if ( mRule == null ) {
return null;
}
final ParserRuleContext parent = mRule.getParent();
if ( parent == null || parent.getChildCount() == 0 ) {
return null;
}
final ParseTree firstParseTree = parent.getChild(0);
if ( ! ( firstParseTree instanceof ParserRuleContext ) ) {
return null;
}
final ParserRuleContext firstRule = (ParserRuleContext) firstParseTree;
return new LocationAST( firstRule, mTokenStream );
}
public void setFirstChild(final LocationAST aNode) {
if ( mRule == null ) {
return;
}
if ( mRule.children == null ) {
mRule.children = new ArrayList<ParseTree>();
}
final List<ParseTree> children = mRule.children;
children.set(0, aNode.getRule());
}
public LocationAST getNextSibling() {
final int childIndex = getChildIndex();
if ( childIndex < 0 ) {
// mRule or mRule.getParent() or mRule.getParent().children is null
return null;
}
final ParserRuleContext parent = mRule.getParent();
if ( childIndex + 1 >= parent.getChildCount() ) {
// current node is the last child, there is no next sibling
return null;
}
final ParseTree nextParseTree = parent.getChild( childIndex + 1 );
if ( ! ( nextParseTree instanceof ParserRuleContext ) ) {
return null;
}
final ParserRuleContext nextRule = (ParserRuleContext) nextParseTree;
return new LocationAST( nextRule, mTokenStream );
}
public void setNextSibling(final LocationAST aNode ) {
final int childIndex = getChildIndex();
if ( childIndex < 0 ) {
// mRule or mRule.getParent() or mRule.getParent().children is null
return;
}
final List<ParseTree> children = mRule.getParent().children;
children.set(childIndex + 1, aNode.getRule());
}
public void addChild(final LocationAST aNode) {
if ( mRule == null ) {
return;
}
if ( mRule.children == null ) {
mRule.children = new ArrayList<ParseTree>();
}
final List<ParseTree> children = mRule.children;
children.add(aNode.getRule());
}
public void removeChildren() {
if ( mRule == null ) {
return;
}
final List<ParseTree> children = mRule.children;
if ( children != null ) {
children.clear();
}
}
public CommonHiddenStreamToken getHiddenBefore() {
return mHiddenBefore;
}
public void setHiddenBefore(final CommonHiddenStreamToken aToken) {
mHiddenBefore = aToken;
}
public CommonHiddenStreamToken getHiddenAfter() {
return mHiddenAfter;
}
public void setHiddenAfter(final CommonHiddenStreamToken aToken) {
mHiddenAfter = aToken;
}
/**
* @return the index of the current node in its parent's child list
* -1 if there is no parent (root node)
*/
private int getChildIndex() {
if ( mRule == null ) {
return -1;
}
final ParserRuleContext parent = mRule.getParent();
if ( parent == null ) {
// no parent (root node)
return -1;
}
if ( parent.children == null ) {
// it should not happen, program error:
// parent's children list is not filled
return -1;
}
for ( int i = 0; i < parent.getChildCount(); i++ ) {
final ParseTree child = parent.getChild(i);
if ( this.mRule == child ) {
return i;
}
}
// it should not happen, program error:
// children list is empty, or current node is not listed in the children list of its parent, or wrong parent
return -1;
}
public int getType() {
//TODO: implement
return 0;
}
public TokenStream getTokenStream() {
return mTokenStream;
}
public void setTokenStream(TokenStream mTokenStream) {
this.mTokenStream = mTokenStream;
}
}
......@@ -27,19 +27,6 @@ public class TITANMarker {
this.priority = priority;
}
public TITANMarker(final String message, final ILocationAST start, final ILocationAST end, final int severity, final int priority) {
this.message = message;
if (start != null) {
this.line = start.getLine();
this.offset = start.getOffset();
}
if (end != null) {
this.endOffset = end.getEndOffset();
}
this.severity = severity;
this.priority = priority;
}
public String getMessage() {
return message;
}
......
......@@ -9,7 +9,6 @@ package org.eclipse.titan.common.parsers.cfg;
import org.antlr.v4.runtime.Token;
import org.eclipse.core.resources.IFile;
import org.eclipse.titan.common.parsers.ILocationAST;
/**
* The Location class represents a location in configuration files. It was
......@@ -29,18 +28,10 @@ public final class CfgLocation {
setLocation(location);
}
public CfgLocation(final IFile file) {
this(file, (ILocationAST)null, (ILocationAST)null);
}
public CfgLocation(final IFile file, final int line, final int offset, final int endOffset) {
setLocation(file, line, offset, endOffset);
}
public CfgLocation(final IFile file, final ILocationAST startTok, final ILocationAST endTok) {
setLocation(file, startTok, endTok);
}
/**
* Constructor for ANTLR v4 tokens
* @param aFile the parsed file
......@@ -55,22 +46,6 @@ public final class CfgLocation {
aEndToken.getStopIndex()+1);
}
private final void setLocation(final IFile file, final ILocationAST startTok, final ILocationAST endTok) {
this.file = file;
if (startTok == null) {
line = -1;
offset = -1;
} else {
line = startTok.getLine();
offset = startTok.getOffset();
}
if (endTok == null) {
endOffset = -1;
} else {
endOffset = endTok.getEndOffset();
}
}
private final void setLocation(final CfgLocation location) {
file = location.getFile();
line = location.getLine();
......
......@@ -39,23 +39,24 @@ import java.util.regex.Pattern;
// pattern for matching typed macro string, for example: ${a, float}
private final static Pattern PATTERN_TYPED_MACRO = Pattern.compile("\\$\\s*\\{\\s*([A-Za-z][A-Za-z0-9_]*)\\s*,\\s*[A-Za-z][A-Za-z0-9_]*\\s*\\}");
private List<TITANMarker> mWarnings = new ArrayList<TITANMarker>();
private List<ISection> mSections = new ArrayList<ISection>();
private Map<String, CfgDefinitionInformation> mDefinitions = new HashMap<String, CfgDefinitionInformation>();
private List<String> mIncludeFiles = new ArrayList<String>();
private IFile mActualFile = null;
private Map<String, String> mEnvVariables;
private CfgParseResult mCfgParseResult = new CfgParseResult();
private int mLine = 1;
private int mOffset = 0;
private ModuleParameterSectionHandler moduleParametersHandler = new ModuleParameterSectionHandler();
private TestportParameterSectionHandler testportParametersHandler = new TestportParameterSectionHandler();
private ComponentSectionHandler componentSectionHandler = new ComponentSectionHandler();
......@@ -67,7 +68,7 @@ import java.util.regex.Pattern;
private IncludeSectionHandler orderedIncludeSectionHandler = new IncludeSectionHandler();
private DefineSectionHandler defineSectionHandler = new DefineSectionHandler();
private LoggingSectionHandler loggingSectionHandler = new LoggingSectionHandler();
public void reportWarning(TITANMarker marker){
mWarnings.add(marker);
}
......@@ -75,7 +76,7 @@ import java.util.regex.Pattern;
public List<TITANMarker> getWarnings(){
return mWarnings;
}
public List<ISection> getSections() {
return mSections;
}
......@@ -83,7 +84,7 @@ import java.util.regex.Pattern;
public void setDefinitions( Map<String,CfgDefinitionInformation> aDefs ) {
mDefinitions = aDefs;
}
public Map< String, CfgDefinitionInformation > getDefinitions() {
return mDefinitions;
}
......@@ -99,11 +100,11 @@ import java.util.regex.Pattern;
public CfgParseResult getCfgParseResult() {
return mCfgParseResult;
}
public void setEnvironmentalVariables(Map<String, String> aEnvVariables){
mEnvVariables = aEnvVariables;
}
public ModuleParameterSectionHandler getModuleParametersHandler() {
return moduleParametersHandler;
}
......@@ -143,7 +144,7 @@ import java.util.regex.Pattern;
public LoggingSectionHandler getLoggingSectionHandler() {
return loggingSectionHandler;
}
/**
* Creates a marker.
* Locations of input tokens are not moved by offset and line yet, this function does this conversion.
......@@ -196,7 +197,7 @@ import java.util.regex.Pattern;
return null;
}
}
/**
* Extracts macro name from macro string
* @param aMacroString macro string, for example: \$a, \${a}
......@@ -210,7 +211,7 @@ import java.util.regex.Pattern;
return null;
}
}
/**
* Extracts macro name from typed macro string
* @param aMacroString macro string, for example: \${a, float}
......@@ -224,7 +225,7 @@ import java.util.regex.Pattern;
return null;
}
}
/**
* Gets the macro value string of a macro (without type)
* @param aMacroToken the macro token
......@@ -243,7 +244,7 @@ import java.util.regex.Pattern;
}
return value;
}
/**
* Gets the macro value string of a macro (without type)
* @param aMacroRule the macro rule
......@@ -262,7 +263,7 @@ import java.util.regex.Pattern;
}
return value;
}
/**
* Gets the macro value string of a macro (with type)
* @param aMacroToken the macro token
......@@ -281,7 +282,7 @@ import java.util.regex.Pattern;
}
return value;
}
/**
* Gets the macro value string of a macro (with type)
* @param aMacroRule the macro rule
......@@ -299,7 +300,7 @@ import java.util.regex.Pattern;
return "";
}
return value;
}
}
}
options{
......@@ -315,22 +316,23 @@ pr_ConfigFile:
)+
EOF
;
pr_Section returns [ ISection section ]:
{ $section = null;
}
( pr_MainControllerSection
| i = pr_IncludeSection { $section = $i.includeSection; includeSectionHandler.setLastSectionRoot( $i.ctx ); }
| pr_OrderedIncludeSection
| pr_ExecuteSection
| d = pr_DefineSection { defineSectionHandler.setLastSectionRoot( $d.ctx ); }
| pr_ExternalCommandsSection
| pr_TestportParametersSection
| pr_GroupsSection
| pr_ModuleParametersSection