List of usage examples for org.antlr.v4.runtime Token getText
String getText();
From source file:edu.clemson.cs.r2jt.absynnew.ResolveCompiler.java
License:Open Source License
private void findDependencies(DefaultDirectedGraph g, ModuleAST root) { for (Token importRequest : root.getImports().getImportsExcluding(ImportCollectionAST.ImportType.EXTERNAL)) { File file = findResolveFile(importRequest.getText(), NATIVE_EXT); ModuleAST module = myModules.get(importRequest); if (module == null) { module = createModuleAST(file); myModules.put(id(module), module); myFiles.put(id(module), file); }// w w w .j a v a 2 s .c o m if (root.getImports().inCategory(ImportCollectionAST.ImportType.IMPLICIT, importRequest)) { if (!module.appropriateForImport()) { throw new IllegalArgumentException("invalid import " + module.getName() + "; cannot import module of " + "type: " + module.getClass()); } } if (pathExists(g, id(module), id(root))) { throw new CircularDependencyException("circular dependency detected"); } Graphs.addEdgeWithVertices(g, id(root), id(module)); findDependencies(g, module); } addFilesForExternalImports(root); }
From source file:edu.clemson.cs.r2jt.absynnew.ResolveCompiler.java
License:Open Source License
private void addFilesForExternalImports(ModuleAST m) { Set<Token> externals = m.getImports().getImportsOfType(ImportCollectionAST.ImportType.EXTERNAL); for (Token externalImport : externals) { File file = findResolveFile(externalImport.getText(), NON_NATIVE_EXT); myFiles.put(new ModuleIdentifier(externalImport), file); }//from ww w.j a va2s . c om }
From source file:edu.clemson.cs.r2jt.absynnew.TreeUtil.java
License:Open Source License
/** * <p>Returns the appropriate RESOLVE function name for the operator * appearing in {@link Token} <code>op</code>. Note that the name returned * is contingent on the naming of the operations in the 'standard' templates * (e.g. <tt>Integer_Template</tt>, <tt>Boolean_Template</tt>, etc).</p> * * <p>So it's important to realize that if one of these 'standard' operation * name's changes, that this method is updated to reflect the new name, * or {@link edu.clemson.cs.r2jt.typeandpopulate2.PopulatingVisitor} * will fail to find the operation (or worse, find a wrong one).</p> * @param op A syntactic operator (<tt>+, -, *</tt>) as would appear * in user sourcecode./*w ww . j a va2s . com*/ * @return The name of the * {@link edu.clemson.cs.r2jt.absynnew.decl.OperationSigAST} * representing the operator <code>op</code>. */ public static Token getTemplateOperationNameFor(Token op) { String result; if (op == null) { throw new IllegalArgumentException("op passed is null"); } switch (op.getType()) { case ResolveParser.Add: result = "Sum"; break; case ResolveParser.Subtract: result = "Difference"; break; case ResolveParser.Multiply: result = "Product"; break; case ResolveParser.Divide: result = "Divide"; break; case ResolveParser.GT: result = "Greater"; break; case ResolveParser.LT: result = "Less"; break; case ResolveParser.LTEquals: result = "Less_Or_Equal"; break; case ResolveParser.GTEquals: result = "Greater_Or_Equal"; break; case ResolveParser.NEquals: result = "Are_Not_Equal"; break; case ResolveParser.Equals: result = "Are_Equal"; break; case ResolveParser.And: result = "And"; break; case ResolveParser.Or: result = "Or"; break; case ResolveParser.Not: result = "Not"; break; default: result = op.getText(); break; } return new ResolveToken(result); }
From source file:edu.clemson.cs.r2jt.rewriteprover.absyn2.PExpr.java
License:Open Source License
private final static String fullName(Token qualifier, String name) { String retval;/*from ww w. j av a 2 s.c o m*/ if (qualifier == null) { retval = ""; } else { if (qualifier.getText() == null) { retval = ""; } else { retval = qualifier.getText() + "."; } } return retval + name; }
From source file:edu.clemson.cs.r2jt.typeandpopulate.ModuleIdentifier.java
License:Open Source License
public ModuleIdentifier(Token t) { this(t.getText()); }
From source file:edu.clemson.cs.r2jt.typeandpopulate2.PopulatingVisitor.java
License:Open Source License
private void putOperationLikeThingInSymbolTable(Token name, TypeAST returnTy, ResolveAST o) { try {/*ww w . ja v a 2s . com*/ PTType returnType; if (returnTy == null) { returnType = PTVoid.getInstance(myTypeGraph); } else { returnType = returnTy.getProgramTypeValue(); } myBuilder.getInnermostActiveScope().addOperation(name.getText(), o, myCurrentParameters, returnType); } catch (DuplicateSymbolException dse) { duplicateSymbol(name); } }
From source file:edu.clemson.cs.r2jt.typeandpopulate2.PopulatingVisitor.java
License:Open Source License
@Override public void postNamedTypeAST(NamedTypeAST e) { //Note that all mathematical types are MathTypeASTs, so this must //be in a program-type syntactic slot. Token tySymbol = e.getName(); Token tyQualifier = e.getQualifier(); String tyName = tySymbol.getText(); try {/* w w w . jav a2 s.c o m*/ ProgramTypeEntry type = myBuilder .getInnermostActiveScope().queryForOne(new NameQuery(tyQualifier, tySymbol, ImportStrategy.IMPORT_NAMED, FacilityStrategy.FACILITY_INSTANTIATE, true)) .toProgramTypeEntry(e.getName()); e.setProgramTypeValue(type.getProgramType()); e.setMathType(myTypeGraph.CLS); e.setMathTypeValue(type.getModelType()); } catch (NoSuchSymbolException nsse) { noSuchSymbol(tyQualifier, tySymbol); } catch (DuplicateSymbolException dse) { //TODO : Error gracefully throw new RuntimeException(dse); } }
From source file:edu.clemson.cs.r2jt.typeandpopulate2.PopulatingVisitor.java
License:Open Source License
@Override public void preProgDotAST(ProgDotAST e) { //Dot expressions are handled ridiculously, even for this compiler, so //this method just deals with the cases we've encountered so far and //lots of assumptions are made. Expect it to break frequently when you //encounter some new case Token firstNameTok = e.getSegments().get(0).getName(); String firstName = firstNameTok.getText(); try {/*from www .java2 s.c o m*/ ProgramVariableEntry eEntry = myBuilder.getInnermostActiveScope() .queryForOne(new NameQuery(null, firstName)).toProgramVariableEntry(firstNameTok); e.getSegments().get(0).setProgramType(eEntry.getProgramType()); e.getSegments().get(0).setMathType(eEntry.getProgramType().toMath()); PTType eType = eEntry.getProgramType(); if (eType instanceof PTRepresentation) { eType = ((PTRepresentation) eType).getBaseType(); } PTRecord recordType = (PTRecord) eType; String fieldName = e.getSegments().get(1).getName().getText(); PTType fieldType = recordType.getFieldType(fieldName); if (fieldType == null) { throw new RuntimeException("Could not retrieve type of " + " field '" + fieldName + "'. Either it doesn't exist " + "in the record or it's missing a type."); } e.getSegments().get(1).setProgramType(fieldType); e.setProgramType(fieldType); e.getSegments().get(1).setMathType(fieldType.toMath()); e.setMathType(fieldType.toMath()); } catch (NoSuchSymbolException nsse) { noSuchSymbol(null, firstNameTok); } catch (DuplicateSymbolException dse) { //This flavor of name query shouldn't be able to throw this--we're //only looking in the local module so there's no overloading throw new RuntimeException(dse); } }
From source file:edu.clemson.cs.r2jt.typeandpopulate2.PopulatingVisitor.java
License:Open Source License
/** * <p>This method has to do an annoying amount of work, so pay attention: * takes an iterator over segments as returned from DotExp.getSegments(). * Either the first segment or first two segments will be advanced over * from the iterator, depending on whether this method determines the DotExp * refers to a local value (one segment), is a qualified name referring to * a value in another module (two segments), or is a Conc expression (two * segments). The segments will receive appropriate types. The data field * of lastGood will be set with the location of the last segment read. * Then, the <code>MathSymbolEntry</code> corresponding to the correct * top-level value will be returned.</p> */// w w w . ja v a 2 s . c o m private MathSymbolEntry getTopLevelValue(Iterator<MathSymbolAST> segments, Indirect<MathSymbolAST> lastGood) { MathSymbolEntry result = null; MathSymbolAST first = segments.next(); Token firstName = first.getName(); //First, we'll see if we're a Conc expression if (firstName.getText().equals("Conc")) { //Awesome. We better be in a type definition and our second segment //better refer to the exemplar MathSymbolAST second = segments.next(); if (!second.toString().equals(myTypeDefinitionEntry.getProgramType().getExemplarName())) { throw new RuntimeException("No idea what's going on here."); } //The Conc segment doesn't have a sensible type, but we'll set one //for completeness. first.setMathType(myTypeGraph.BOOLEAN); second.setMathType(myTypeDefinitionEntry.getModelType()); result = myTypeDefinitionEntry.getExemplar(); lastGood.data = second; } else { //Next, we'll see if there's a locally-accessible symbol with this //name try { result = myBuilder .getInnermostActiveScope().queryForOne(new NameQuery(first.getQualifier(), firstName, ImportStrategy.IMPORT_NAMED, FacilityStrategy.FACILITY_IGNORE, true)) .toMathSymbolEntry(first.getStart()); //There is. Cool. We type it and we're done lastGood.data = first; first.setMathType(result.getType()); try { first.setMathTypeValue(result.getTypeValue()); } catch (SymbolNotOfKindTypeException snokte) { } } catch (NoSuchSymbolException nsse) { noSuchSymbol(first.getQualifier(), first.getName()); } catch (DuplicateSymbolException dse) { duplicateSymbol(firstName); throw new RuntimeException(); //This will never fire } } return result; }
From source file:edu.clemson.cs.r2jt.typeandpopulate2.PopulatingVisitor.java
License:Open Source License
private MathSymbolEntry postSymbolExp(Token qualifier, Token symbolName, ExprAST node) { MathSymbolEntry intendedEntry = getIntendedEntry(qualifier, symbolName, node); node.setMathType(intendedEntry.getType()); setSymbolTypeValue(node, symbolName.getText(), intendedEntry); String typeValueDesc = ""; if (node.getMathTypeValue() != null) { typeValueDesc = ", referencing math type " + node.getMathTypeValue() + " (" + node.getMathTypeValue().getClass() + ")"; }//from www . ja va2 s. c om PopulatingVisitor .emitDebug("processed symbol " + symbolName + " with type " + node.getMathType() + typeValueDesc); return intendedEntry; }