Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/* Alloy Analyzer 4 -- Copyright (c) 2006-2009, Felix Chang
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package edu.mit.csail.sdg.parser;
import static edu.mit.csail.sdg.ast.Sig.SEQIDX;
import static edu.mit.csail.sdg.ast.Sig.SIGINT;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import edu.mit.csail.sdg.alloy4.A4Reporter;
import edu.mit.csail.sdg.alloy4.ConstList;
import edu.mit.csail.sdg.alloy4.Err;
import edu.mit.csail.sdg.alloy4.ErrorFatal;
import edu.mit.csail.sdg.alloy4.ErrorSyntax;
import edu.mit.csail.sdg.alloy4.Pos;
import edu.mit.csail.sdg.alloy4.Util;
import edu.mit.csail.sdg.ast.Command;
import edu.mit.csail.sdg.ast.Expr;
import edu.mit.csail.sdg.ast.ExprCall;
import edu.mit.csail.sdg.ast.ExprUnary;
import edu.mit.csail.sdg.ast.ExprUnary.Op;
import edu.mit.csail.sdg.ast.Module;
import edu.mit.csail.sdg.ast.Sig;
import edu.mit.csail.sdg.ast.Sig.Field;
import edu.mit.csail.sdg.ast.Type.ProductType;
import edu.mit.csail.sdg.ast.VisitQueryOnce;
import edu.mit.csail.sdg.parser.CompModule.Open;
/**
* This class provides convenience methods for calling the parser and the
* compiler.
*/
public final class CompUtil {
/**
* Constructor is private, since this class never needs to be instantiated.
*/
private CompUtil() {}
// =============================================================================================================//
/**
* Go up the directory hierachy 0 or more times.
* For example, on a UNIX machine, goUp("/home/abc/def",1) will return
* "/home/abc"
* For example, on a UNIX machine, goUp("/home/abc/def",2) will return "/home"
*
* @param filepath - this must be an absolute path
* @param numberOfSteps - the number of steps to go up
*/
private static String up(String filepath, int numberOfSteps) {
while (numberOfSteps > 0) {
numberOfSteps--;
int i = filepath.lastIndexOf(File.separatorChar);
if (i <= 0)
return "";
filepath = filepath.substring(0, i);
}
return filepath;
}
// =============================================================================================================//
/**
* Given the name of a module, and the filename for that module, compute the
* filename for another module
*
* @param moduleA - must be a legal Alloy modulepath (eg. name) (eg.
* name/name/name) (must not start or end in '/')
* @param fileA - the filename corresponding to moduleA
* @param moduleB - must be a legal Alloy modulepath (eg. name) (eg.
* name/name/name) (must not start or end in '/')
* @return the filename corresponding to moduleB
*/
private static String computeModulePath(String moduleA, String fileA, String moduleB) {
fileA = Util.canon(fileA); // Make sure it's a canonical absolute path
if (moduleA.length() == 0)
moduleA = "anything"; // Harmonizes the boundary case
while (moduleA.length() > 0 && moduleB.length() > 0) {
int a = moduleA.indexOf('/'), b = moduleB.indexOf('/');
String headOfA = (a >= 0) ? moduleA.substring(0, a) : moduleA;
String headOfB = (b >= 0) ? moduleB.substring(0, b) : moduleB;
if (!headOfA.equals(headOfB) || a < 0 || b < 0) {
// eg. util/boolean==/home/models/util/boolean.als, then
// test=>/home/models/test.als"
// eg. util/boolean==/home/models/util/boolean.als, then
// sub/test=>/home/models/sub/test.als
// eg. main==/home/models/main.als, then
// test=>/home/models/test.als
// eg. main==/home/models/main.als, then
// sub/test=>/home/models/sub/test.als"
int numberOfSlash = 0;
for (int i = 0; i < moduleA.length(); i++)
if (moduleA.charAt(i) == '/')
numberOfSlash++;
return up(fileA, numberOfSlash + 1) + File.separatorChar + moduleB.replace('/', File.separatorChar) + ".als";
}
moduleA = moduleA.substring(a + 1);
moduleB = moduleB.substring(b + 1);
}
return ""; // This shouldn't happen, since there should always be some
// character after '/' in the module name
}
// =============================================================================================================//
/**
* Whether or not Int appears in the relation types found in these sigs
*/
public static boolean areIntsUsed(Iterable sigs, Command cmd) {
/* check for Int-typed relations */
for (Sig s : sigs) {
for (Field f : s.getFields()) {
for (ProductType pt : f.type()) {
for (int k = 0; k < pt.arity(); k++) {
if (pt.get(k) == SIGINT || pt.get(k) == SEQIDX)
return true;
}
}
}
}
if (cmd == null)
return false;
/* check expressions; look for CAST2SIGING (Int[]) */
try {
Object intTriggerNode;
intTriggerNode = cmd.formula.accept(new VisitQueryOnce