Commit bb13bb17 authored by Leonard Faecke's avatar Leonard Faecke
Browse files

+ Added specific analysis in analyzer

* Made filenames in resulting file optional
parent 88d0c697
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@
    <booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
    <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
    <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
    <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
    <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="de.ugoe.cs.swe.T3Q.T3Q"/>
    <stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="de.ugoe.cs.swe.T3Q"/>
    <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--config config/t3q.cfg --profile defaultProfile C:\Users\leofa\Documents\_t3q\iwd\iwd-TTCN3-B2013-03_D14wk10 --analyze-usage"/>
    <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--config config/t3q.cfg --profile defaultProfile C:\Users\leofa\Documents\_t3q\examples --analyze-usage"/>
    <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="de.ugoe.cs.swe.T3Q"/>
    <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
    <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms7g -Xmx10g"/>
    <stringAttribute key="yk-options" value="&#13;&#10;additional-options2=onexit\=snapshot&#13;&#10;"/>
</launchConfiguration>
+2 −0
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@
    <booleanAttribute key="org.eclipse.jdt.launching.ATTR_SHOW_CODEDETAILS_IN_EXCEPTION_MESSAGES" value="true"/>
    <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_CLASSPATH_ONLY_JAR" value="false"/>
    <booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
    <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
    <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="de.ugoe.cs.swe.T3Q.T3Q"/>
    <stringAttribute key="org.eclipse.jdt.launching.MODULE_NAME" value="de.ugoe.cs.swe.T3Q"/>
    <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--config config/t3q.cfg --profile defaultProfile"/>
    <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="de.ugoe.cs.swe.T3Q"/>
    <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
    <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms256m -Xmx4g"/>
    <stringAttribute key="yk-options" value="&#13;&#10;additional-options2=onexit\=snapshot&#13;&#10;"/>
</launchConfiguration>
+28 −0
Original line number Diff line number Diff line
T3Q v2.1.0b1
TTCN-3 version supported: 4.6.1
==========================================
ERROR: Missing input location(s)

Help:
  Usage: t3q [options] (filename | path)+
  Options: (in any order, config is required)
    --generate-config <FILE NAME>   Generate a new default configuration
                                    file at the specified file location
    --config <FILE NAME>            Configuration file location
                                    
    --profile <PROFILE NAME>        Configuration profile
                                    
    --verbosity <LOG LEVEL>         Verbosity level (currently supports
                                    ERROR, WARNING and INFORMATION values)
    --output-path <PATH>            Destination path for the output (if
                                    applicable, otherwise ignored),
                                    overrides the profile setting
    --help                          Show this usage information screen
                                    
    --local-dependencies            Generate local dependencies
                                    
    --single-core                   Use single core only (no parallel
                                    processing)
    --analyze-usage                 Collect language usage information
                                    
+20 −13
Original line number Diff line number Diff line
@@ -318,8 +318,10 @@ public class TTCN3ResourceProvider {
			List<Future<TTCN3Usage>> output = pool.invokeAll(analyzer);
			pool.shutdown();
			System.out.print('\n');
			boolean filenames = false;
			List<Map<String, Long>> maps = new ArrayList<>();
			String name = new File(paths.get(0)).getName();
			if(filenames) {
				for (Future<TTCN3Usage> f : output) {
					TTCN3Usage o = f.get();
					String pathName = String.join("/", o.getResource().getURI().segments());
@@ -332,10 +334,15 @@ public class TTCN3ResourceProvider {
					//printOutput(o.getResource(), newMap);
					maps.add(newMap);
				}
			
			} else {
				for (Future<TTCN3Usage> f : output) {
					TTCN3Usage o = f.get();
					maps.add(o.getOutput());
				}
			}
			Map<String, Long> unified = unifyMaps(maps);
			
			System.out.println("Total usage analysis output:");
			//System.out.println("Total usage analysis output:");
			//printOutput(unified);
			
			saveJson(unified, name + ".json");
@@ -543,7 +550,7 @@ public class TTCN3ResourceProvider {
			BufferedWriter writer = new BufferedWriter(new FileWriter(new File(dir, name)), dataLimit);
			writer.write(jsonString);
			writer.flush();
			//gson.toJson(json, new FileWriter(new File(dir, name))); //FileWriter has a limit at 8192 characters
			//gson.toJson(json, new FileWriter(new File(dir, name)));
		} catch (IOException e) {
			e.printStackTrace();
		}
+255 −15
Original line number Diff line number Diff line
@@ -89,7 +89,8 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> {
			//analyzeModule(module, output);
			
			//make gson of every model
			Map<String, Long> json= genericAnalysisSingle(module.eContainer());
			Map<String, Long> json = specificAnalysisSingle(module);
			//Map<String, Long> json= genericAnalysisSingle(module.eContainer());
			allJsons.add(json);
		}
		
@@ -183,6 +184,67 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> {
		//--------------------------------------------------------
	}
	
	private Map<String, Long> specificAnalysisSingle(TTCN3Module module) {
		Map<String, Long> results = new HashMap<>();
		
		
		//Fuzzy, Lazy
		
		analyzeEvaluation(module, results);
		
		//Anytype
		
		analyzeTypes(module, results);
		
		//opentype (not supported)
		
		//automatic type (not supported)
		
		//operators
		
		analyzeOperators(module, results);
		
		//decoded field reference
		
		analyzeDecodedField(module, results);
		
		//groups
		
		analyzeGroups(module, results);
		
		//imports
		List<ImportDef> imports = EcoreUtil2.getAllContentsOfType(module, ImportDef.class);
		for(ImportDef importDef : imports) {
			analyzeImportDef(importDef, results);
		}
		
		//visibility
		
		analyzeVisibility(module, results);
		
		//trigger
		
		analyzeTrigger(module, results);
		
		//check
		
		analyzeCheck(module, results);
		
		//controlling communication ports
		
		analyzeControllingPorts(module, results);
		
		//external actions
		
		analyzeExternalActions(module, results);
		
		//specifying attributes
		
		analyzeSpecifyingAttributes(module, results);
		
		return results;
	}
	
	/**
	 * Counts all definitions within a module.
	 * Currently obsolete. Replaced by manual tree traversal
@@ -327,6 +389,9 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> {
		addNToOutput(output, identifier, (long) 1);
	}
	
	private void addToOutput(Map<String, Long> output, String identifier) {
		addNToOutput(output, identifier, 1);
	}
	
	/**
	 * Add n to the given identifier in the output
@@ -342,6 +407,14 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> {
		}
	}
	
	private void addNToOutput(Map<String, Long> output, String identifier, int v) {
		if(output.containsKey(identifier)) {
			output.replace(identifier, output.get(identifier) + v);
		} else {
			output.put(identifier, (long) v);
		}
	}
	
	/**
	 * Analyzes a module on its content
	 * @param module The module to be analyzed
@@ -360,7 +433,7 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> {
			} else if (def.getDef().getClass() == FunctionDefImpl.class) {
				analyzeFunctionDef((FunctionDef) def.getDef(), output);
			} else if(def.getDef().getClass() == ImportDefImpl.class) {
				analyzeImportDef((ImportDef) def.getDef(), output);
				//analyzeImportDef((ImportDef) def.getDef(), output);
			} else if(def.getDef().getClass() == GroupDefImpl.class) {
				analyzeGroupDef((GroupDef) def.getDef(), output);
			} else if(def.getDef().getClass() == TemplateDefImpl.class) {
@@ -456,21 +529,43 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> {
	 * @param imp The import definition to be analyzed
	 * @param output The TTCN3Usage to write the output to
	 */
	private void analyzeImportDef(ImportDef imp, TTCN3Usage output) {
		System.out.println("Analyzing import");
		String impType = "Import";
		if(imp.getAll() == null && imp.getImportSpec() == null && imp.getSpec() == null) {
			impType += "null"; //Import statement that does not import something, should not happen
		} else if(imp.getImportSpec() != null) { //Q: does anything apart from size matter?
			impType += imp.getImportSpec().getElement().size() + "Specified";
		} else if(imp.getAll() != null) {
			impType += "All";
			if(imp.getAll().getDef() != null) {
				impType += "With" + imp.getAll().getDef().getSpec().getElement().size() + "Except";
			}
	private void analyzeImportDef(ImportDef imp, Map<String, Long> output) {
		addToOutput(output, "ImportDef");
		AllWithExcepts all = imp.getAll();
		if(all != null) {
			if(all.getDef() == null) {
				addToOutput(output, "ImportAll");
			} else {
				addToOutput(output, "ImportAllExcept");
			}
		} else {
			//specified
			ImportSpec spec = imp.getImportSpec();
			addNToOutput(output, "ImportElement", spec.getElement().size());
			for(ImportElement el : spec.getElement()) {
				if(el.getAltstep() != null) addToOutput(output, "ImportAltstepSpec");
				else addNToOutput(output, "ImportAltstepSpec", 0);
				if(el.getConst() != null) addToOutput(output, "ImportConstSpec");
				else addNToOutput(output, "ImportConstSpec", 0);
				if(el.getFunction() != null) addToOutput(output, "ImportFunctionSpec");
				else addNToOutput(output, "ImportFunctionSpec", 0);
				if(el.getGroup() != null) addToOutput(output, "ImportGroupSpec");
				else addNToOutput(output, "ImportGroupSpec", 0);
				if(el.getModulePar() != null) addToOutput(output, "ImportModuleParSpec");
				else addNToOutput(output, "ImportModuleParSpec", 0);
				if(el.getSignature() != null) addToOutput(output, "ImportSignatureSpec");
				else addNToOutput(output, "ImportSignatureSpec", 0);
				if(el.getTemplate() != null) addToOutput(output, "ImportTemplateSpec");
				else addNToOutput(output, "ImportTemplateSpec", 0);
				if(el.getTestcase() != null) addToOutput(output, "ImportTestcaseSpec");
				else addNToOutput(output, "ImportTestcaseSpec", 0);
				if(el.getType() != null) addToOutput(output, "ImportTypeSpec");
				else addNToOutput(output, "ImportTypeSpec", 0);
			}
			addToOutput(output, "ImportSpec");
			//addToOutput(output, spec);
			
		addToOutput(output, impType);
		}
	}
	
	/**
@@ -713,6 +808,151 @@ System.out.println("Analyzing function");
		addNToOutput(output, id, (long) n);
	}
	
	
	private void analyzeEvaluation(TTCN3Module module, Map<String, Long> output) {
		for(FormalTemplatePar t : EcoreUtil2.getAllContentsOfType(module, FormalTemplatePar.class)) {
			if(t.getMod() != null) addToOutput(output, "FormalTemplatePar_" + t.getMod());
			else addNToOutput(output, "FormalTemplatePar_" + t.getMod(), 0);
		}
		for(FormalValuePar t : EcoreUtil2.getAllContentsOfType(module, FormalValuePar.class)) {
			if(t.getMod() != null) addToOutput(output, "FormalValuePar_" + t.getMod());
			else addNToOutput(output, "FormalValuePar_" + t.getMod(), 0);
		}
		for(VarInstance t : EcoreUtil2.getAllContentsOfType(module, VarInstance.class)) {
			if(t.getListMod() != null) addToOutput(output, "VarInstance_" + t.getListMod());
			else addNToOutput(output, "VarInstance_" + t.getListMod(), 0);
			
		}
		for(TemplateDef t : EcoreUtil2.getAllContentsOfType(module, TemplateDef.class)) {
			if(t.getFuzzy() != null) addToOutput(output, "TemplateDef_" + t.getFuzzy());
			else addNToOutput(output, "TemplateDef_" + t.getFuzzy(), 0);
		}
	}
	
	private void analyzeTypes(TTCN3Module module, Map<String, Long> output) {
		for(Type t : EcoreUtil2.getAllContentsOfType(module, Type.class)) {
			if(t.getPre() != null && t.getPre().equals("anytype")) addToOutput(output, "Type_anytype");
			else addNToOutput(output, "Type_anytype", 0);
		}
		for(ExtendedFieldReference t : EcoreUtil2.getAllContentsOfType(module, ExtendedFieldReference.class)) {
			if(t.getType() != null && t.getType().equals("anytype")) addToOutput(output, "ExtendedFieldReference_anytype");
			else addNToOutput(output, "ExtendedFieldReference_anytype", 0);
		}
		for(FieldExpressionSpec t : EcoreUtil2.getAllContentsOfType(module, FieldExpressionSpec.class)) {
			if(t.getType() != null && t.getType().equals("anytype")) addToOutput(output, "FieldExpressionSpec_anytype");
			else addNToOutput(output, "FieldExpressionSpec_anytype", 0);
		}
		for(FieldConstExpressionSpec t : EcoreUtil2.getAllContentsOfType(module, FieldConstExpressionSpec.class)) {
			if(t.getType() != null && t.getType().equals("anytype")) addToOutput(output, "FieldConstExpressionSpec_anytype");
			else addNToOutput(output, "FieldConstExpressionSpec_anytype", 0);
		}
	}
	
	private void analyzeOperators(TTCN3Module module, Map<String, Long> output) {
		//Shift and rotate operators
		for(ShiftExpression exp : EcoreUtil2.getAllContentsOfType(module, ShiftExpression.class)) {
			String operation = "UnkownShiftOperation";
			switch(exp.getOperator()) {
			case "<<":
				operation = "LeftShift";
				break;
			case ">>":
				operation = "RightShift";
				break;
			case "<@":
				operation = "LeftRotate";
				break;
			case "@>":
				operation = "RightRotate";
				break;
			default:
				System.out.println("Unkown Shift operation found");
			}
			addToOutput(output, operation);
		}
		
		//Presence checking operators
		addNToOutput(output, "ispresent", EcoreUtil2.getAllContentsOfType(module, Fispresent.class).size());
		addNToOutput(output, "ischosen", EcoreUtil2.getAllContentsOfType(module, Fischosen.class).size());
		addNToOutput(output, "isvalue", EcoreUtil2.getAllContentsOfType(module, Fisvalue.class).size());
		addNToOutput(output, "isbound", EcoreUtil2.getAllContentsOfType(module, Fisbound.class).size());
	}
	
	private void analyzeDecodedField(TTCN3Module module, Map<String, Long> output) {
		addNToOutput(output, "DecodedFieldReference", EcoreUtil2.getAllContentsOfType(module, DecodedFieldReference.class).size());
		addNToOutput(output, "DecodedFieldType", EcoreUtil2.getAllContentsOfType(module, DecodedFieldType.class).size());
	}
	
	private void analyzeGroups(TTCN3Module module, Map<String, Long> output) {
		//calculate average depth of top level groups

		int sum = 0;
		int groups = 0;
		for(ModuleDefinition def : module.getDefs().getDefinitions()) {
			if(def.getDef().getClass() == GroupDefImpl.class) {
				groups++;
				sum += checkRecursionDepth((GroupDef) def.getDef());
			}
		}
		addNToOutput(output, "TopLevel_GroupDef", groups);
		addNToOutput(output, "Group_RecursionSum", sum);

		//analyze group content
		for(GroupDef group : EcoreUtil2.getAllContentsOfType(module, GroupDef.class)) {
			if(group.getList() == null) continue;
			EcoreUtil2.getAllContainers(group);
			for(ModuleDefinition def : group.getList().getDefinitions()) {
				String name = def.getDef().getClass().getSimpleName();
				addToOutput(output, "InGroup_" + name.substring(0, name.length()-4));
			}
		}
	}
	
	private int checkRecursionDepth(GroupDef group) {
		if(group.getList() == null) return 0;
		List<ModuleDefinition> defs = group.getList().getDefinitions();
		if(defs.size() == 0) return 0;
		int depth = 0;
		for(ModuleDefinition def : defs) {
			if(def.getDef().getClass() == GroupDefImpl.class) 
				depth = Math.max(depth, checkRecursionDepth((GroupDef) def.getDef()) + 1);
		}
		return depth;
	}
	
	private void analyzeVisibility(TTCN3Module module, Map<String, Long> output) {
		for(ModuleDefinition def : EcoreUtil2.getAllContentsOfType(module, ModuleDefinition.class)) {
			addToOutput(output, def.getVisibility().getLiteral());
		}
	}
	
	private void analyzeTrigger(TTCN3Module module, Map<String, Long> output) {
		addNToOutput(output, "Trigger", EcoreUtil2.getAllContentsOfType(module, PortTriggerOp.class).size());
	}
	
	private void analyzeCheck(TTCN3Module module, Map<String, Long> output) {
		addNToOutput(output, "Check", EcoreUtil2.getAllContentsOfType(module, PortCheckOp.class).size());
	}
	
	private void analyzeControllingPorts(TTCN3Module module, Map<String, Long> output) {
		addNToOutput(output, "ClearStatement", EcoreUtil2.getAllContentsOfType(module, ClearStatement.class).size());
		addNToOutput(output, "StartStatement", EcoreUtil2.getAllContentsOfType(module, StartStatement.class).size());
		addNToOutput(output, "StopStatement", EcoreUtil2.getAllContentsOfType(module, StopStatement.class).size());
		addNToOutput(output, "HaltStatement", EcoreUtil2.getAllContentsOfType(module, HaltStatement.class).size());
		addNToOutput(output, "CheckStateStatement", EcoreUtil2.getAllContentsOfType(module, CheckStateStatement.class).size());
	}
	
	private void analyzeExternalActions(TTCN3Module module, Map<String, Long> output) {
		addNToOutput(output, "ExternalActions", EcoreUtil2.getAllContentsOfType(module, SUTStatements.class).size());
	}
	
	private void analyzeSpecifyingAttributes(TTCN3Module module, Map<String, Long> output) {
		for(SingleWithAttrib attrib : EcoreUtil2.getAllContentsOfType(module, SingleWithAttrib.class)) {
			addToOutput(output, "with_" + attrib.getKeyword());
			if(attrib.getOverride() != null) addToOutput(output, "override_" + attrib.getOverride());
		}
	}
	
	@Override
	public TTCN3Usage call() throws Exception {
		return analyze();
Loading