Changeset 459


Ignore:
Timestamp:
Jul 7, 2010 1:22:08 AM (14 years ago)
Author:
Anya Helene Bagge
Message:
  • Have the static checker report TODOs and deprecation info from the grammar + warn about ambiguities
  • Run static checker from builder
  • Disable as-you-type ambiguity checker
  • Experimental direct encoding of trees as constructors/rascal ADTs
Location:
trunk/magnolia-eclipse
Files:
3 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/magnolia-eclipse/build.properties

    r370 r459  
    88               icons/,\
    99               mglib/
    10 src.includes = src/,\
    11                META-INF/,\
    12                plugin.xml,\
    13                mglib/,\
     10src.includes = mglib/,\
    1411               lang/,\
    1512               icons/
  • trunk/magnolia-eclipse/plugin.xml

    r453 r459  
    229229      </persistent>
    230230   </extension>
    231     <extension
     231   <extension
    232232         id="ambiguityMarker"
    233233         name="Ambiguity"
  • trunk/magnolia-eclipse/src/org/magnolialang/eclipse/builders/MagnoliaBuilder.java

    r453 r459  
    2626import org.magnolialang.errors.SyntaxError;
    2727import org.magnolialang.load.ProjectURIResolver;
     28import org.magnolialang.magnolia.StaticChecker;
    2829import org.magnolialang.manager.IModuleInfo;
    2930import org.magnolialang.manager.MagnoliaProjectManager;
     
    147148                        IModuleInfo module = manager.getModule(manager.getModuleName(file));
    148149                        module.getEnv();
     150                        StaticChecker.getInstance().checkModule(module, manager);
    149151                } catch(CompilationError ce) {
    150152                        manager.reportError(ce, "Compiler");
  • trunk/magnolia-eclipse/src/org/magnolialang/eclipse/commands/SelectConstruct.java

    r453 r459  
    3737                                long diffTime = 0;
    3838
     39                                IValue term = RascalInterpreter.getInstance().call("tryme", "import MagnoliaCompile;", tree);
     40
    3941                                startTime = System.nanoTime();
    4042                                imploded = TreeImploder.implodeTree(tree);
    4143                                diffTime = System.nanoTime()-startTime;
    42                                
     44/*                             
    4345                                System.out.printf("Java tree imploder: %fms\n", diffTime/1000000.0);
    4446                                System.out.println("Ready.");
     
    7476                                //MessageDialog.openInformation(
    7577                                //            HandlerUtil.getActiveShell(event),"Inline","You selected:\n" + TreeAdapter.yield(tree));
     78                                 *
     79                                 */
    7680                        }
    7781                        return null;
  • trunk/magnolia-eclipse/src/org/magnolialang/eclipse/editor/AmbiguityMarkerModelListener.java

    r453 r459  
    77import org.eclipse.imp.parser.IParseController;
    88import org.eclipse.imp.pdb.facts.IConstructor;
     9import org.eclipse.imp.pdb.facts.INode;
    910import org.eclipse.imp.pdb.facts.ISet;
    1011import org.eclipse.imp.pdb.facts.ISourceLocation;
     12import org.eclipse.imp.pdb.facts.IString;
    1113import org.eclipse.imp.pdb.facts.IValue;
    1214import org.eclipse.imp.pdb.facts.visitors.VisitorException;
     15import org.rascalmpl.values.uptr.Factory;
    1316import org.rascalmpl.values.uptr.ParsetreeAdapter;
    1417import org.rascalmpl.values.uptr.ProductionAdapter;
     
    2730
    2831        public static void annotateAmbiguities(IConstructor tree, IMessageHandler handler) {
    29                 try {
     32                /*try {
    3033                        if(ParsetreeAdapter.isParseTree(tree))
    3134                                ParsetreeAdapter.getTop(tree).accept(new AmbiguityVisitor(handler));
     
    3336                                tree.accept(new AmbiguityVisitor(handler));
    3437                } catch (VisitorException e) {
    35                 }
     38                }*/
    3639        }
    3740
     
    9497                }
    9598
     99                @Override
     100                public IConstructor visitTreeAppl(IConstructor tree) throws VisitorException {
    96101
    97                 @Override
    98                 public IConstructor visitTreeAppl(IConstructor arg) throws VisitorException {
    99                         for(IValue v : TreeAdapter.getArgs(arg))
     102                        for(IValue v : TreeAdapter.getArgs(tree))
    100103                                v.accept(this);
    101104                        return null;
    102105                }
     106
    103107
    104108
  • trunk/magnolia-eclipse/src/org/magnolialang/eclipse/editor/MagnoliaParseController.java

    r453 r459  
    109109
    110110        public Object parse(String input, IProgressMonitor monitor) {
    111                 parseTree = null;
     111                parseTree = null;
    112112               
    113113                try{
  • trunk/magnolia-eclipse/src/org/magnolialang/eclipse/preferences/MagnoliaInstanceTab.java

    r453 r459  
    33import java.util.List;
    44import java.util.ArrayList;
     5import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
     6import org.eclipse.core.runtime.preferences.IEclipsePreferences;
    57import org.eclipse.swt.widgets.Composite;
    68import org.eclipse.swt.widgets.Link;
    79import org.eclipse.imp.preferences.*;
    810import org.eclipse.imp.preferences.fields.*;
     11import org.osgi.service.prefs.Preferences;
    912
    1013
  • trunk/magnolia-eclipse/src/org/magnolialang/eclipse/preferences/MagnoliaProjectTab.java

    r453 r459  
    33import java.util.List;
    44import java.util.ArrayList;
     5import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
    56import org.eclipse.core.runtime.preferences.IEclipsePreferences;
    67import org.eclipse.swt.widgets.Composite;
  • trunk/magnolia-eclipse/src/org/magnolialang/magnolia/StaticChecker.java

    r448 r459  
    11package org.magnolialang.magnolia;
    22
     3import org.eclipse.core.resources.IMarker;
     4import org.eclipse.core.resources.IResource;
     5import org.eclipse.imp.parser.IMessageHandler;
    36import org.eclipse.imp.pdb.facts.IConstructor;
     7import org.eclipse.imp.pdb.facts.INode;
     8import org.eclipse.imp.pdb.facts.ISet;
     9import org.eclipse.imp.pdb.facts.ISourceLocation;
     10import org.eclipse.imp.pdb.facts.IString;
     11import org.eclipse.imp.pdb.facts.IValue;
     12import org.eclipse.imp.pdb.facts.visitors.VisitorException;
    413import org.magnolialang.env.MagnoliaEnvironment;
     14import org.magnolialang.errors.ErrorMarkers;
     15import org.magnolialang.manager.IModuleInfo;
     16import org.magnolialang.manager.MagnoliaProjectManager;
     17import org.rascalmpl.values.uptr.Factory;
     18import org.rascalmpl.values.uptr.ProductionAdapter;
     19import org.rascalmpl.values.uptr.TreeAdapter;
     20import org.rascalmpl.values.uptr.visitors.TreeVisitor;
    521
    622public class StaticChecker {
     
    1329        }
    1430
    15         public void checkModule(IConstructor tree, MagnoliaEnvironment env) {
    16                 // TODO Auto-generated method stub
     31        public void checkModule(IModuleInfo module, MagnoliaProjectManager manager) {
     32                try {
     33                        module.getParseTreeTop().accept(new StaticCheckVisitor(manager));
     34                } catch (VisitorException e) {
     35                        // TODO Auto-generated catch block
     36                        e.printStackTrace();
     37                }
     38        }
     39
     40
     41        private static class StaticCheckVisitor extends TreeVisitor {
     42                private MagnoliaProjectManager manager;
     43
     44                public StaticCheckVisitor(MagnoliaProjectManager manager) {
     45                        this.manager = manager;
     46                        /*              if(file != null)
     47                        try {
     48                        file.deleteMarkers(AMB_MARKER, true, IResource.DEPTH_INFINITE);
     49                        } catch (CoreException e) {
     50                        }*/
     51                }
     52
     53
     54                @Override
     55                public IConstructor visitTreeAmb(IConstructor tree) throws VisitorException {
     56                        IConstructor child = (IConstructor)TreeAdapter.getAlternatives(tree).iterator().next();
     57                        ISourceLocation loc = TreeAdapter.getLocation(child);
     58
     59
     60                        ISet alts = TreeAdapter.getAlternatives(tree);
     61                        StringBuffer message = new StringBuffer("<p>Ambiguity:\n<ul>\n");
     62                        for(IValue alt : alts) {
     63                                IConstructor prod = TreeAdapter.getProduction((IConstructor)alt);
     64                                message.append("  <li>" + ProductionAdapter.getSortName(prod) + " ::= " + ProductionAdapter.getLhs(prod) + "</li>\n");
    1765               
     66                        }
     67                        message.append("</ul></p>");
     68
     69                        manager.reportError(message.toString(), loc, ErrorMarkers.SYNTAX_ERROR, IMarker.SEVERITY_WARNING);
     70                        return null;
     71                }
     72
     73                @Override
     74                public IConstructor visitTreeAppl(IConstructor tree) throws VisitorException {
     75                        IConstructor prod = TreeAdapter.getProduction(tree);
     76                        if(prod != null)
     77                        for (IValue attr : ProductionAdapter.getAttributes(prod)) {
     78                                if (attr != null && attr.getType().isAbstractDataType() && ((IConstructor) attr).getConstructorType() == Factory.Attr_Term) {
     79                                        IValue value = ((IConstructor)attr).get("term");
     80                                        if (value.getType().isNodeType() && ((INode) value).getName().equals("todo")) {
     81                                                ISourceLocation loc = TreeAdapter.getLocation(tree);
     82                                                manager.reportError("TODO: " + ((IString) ((INode) value).get(0)).getValue(), loc, ErrorMarkers.COMPILATION_ERROR, IMarker.SEVERITY_INFO);
     83                                        }
     84                                        else if (value.getType().isNodeType() && ((INode) value).getName().equals("deprecated")) {
     85                                                INode node = (INode)value;
     86                                                String message = "Deprecated construct or syntax";
     87                                                if(node.arity() > 0)
     88                                                        message = message + ": " + ((IString)node.get(0)).getValue();
     89                                                ISourceLocation loc = TreeAdapter.getLocation(tree);
     90                                                manager.reportError(message, loc, ErrorMarkers.COMPILATION_ERROR, IMarker.SEVERITY_WARNING);
     91                                        }
     92                                }
     93                        }
     94                        for(IValue v : TreeAdapter.getArgs(tree))
     95                                v.accept(this);
     96                        return null;
     97                }
     98
     99
     100
     101                @Override
     102                public IConstructor visitTreeChar(IConstructor arg) throws VisitorException {
     103                        return null;
     104                }
     105
     106
     107                @Override
     108                public IConstructor visitTreeCycle(IConstructor arg)
     109                throws VisitorException {
     110                        return null;
     111                }
    18112        }
    19113
  • trunk/magnolia-eclipse/src/org/magnolialang/manager/FileModuleInfo.java

    r453 r459  
    88import org.eclipse.core.resources.IResource;
    99import org.eclipse.core.runtime.CoreException;
     10import org.eclipse.imp.pdb.facts.IConstructor;
    1011import org.magnolialang.errors.ImplementationError;
    1112import org.magnolialang.errors.ModuleNotFoundError;
  • trunk/magnolia-eclipse/src/org/magnolialang/manager/IModuleInfo.java

    r452 r459  
    1212        public abstract IConstructor getTree();
    1313
     14        public abstract IConstructor getParseTree();
     15       
     16        public abstract IConstructor getParseTreeTop();
     17       
    1418        public abstract MagnoliaEnvironment getEnv();
    1519       
  • trunk/magnolia-eclipse/src/org/magnolialang/manager/MagnoliaModuleInfo.java

    r453 r459  
    100100                return tree;
    101101        }
     102
     103        public IConstructor getParseTree() {
     104                if(parseTree == null || isModified())
     105                        if(!loadTree()) {
     106                                throw new ImplementationError("Loading tree failed for module " + getModuleName());
     107                        }
     108                assert parseTree != null;
     109                return parseTree;
     110        }
    102111       
     112        public IConstructor getParseTreeTop() {
     113                IConstructor pt = getParseTree();
     114                if(pt != null && ParsetreeAdapter.isParseTree(pt))
     115                        return ParsetreeAdapter.getTop(pt);
     116                else
     117                        return pt;
     118        }
     119
    103120        public MagnoliaEnvironment getEnv() {
    104121                getTree();
  • trunk/magnolia-eclipse/src/org/magnolialang/manager/MagnoliaProjectManager.java

    r453 r459  
    146146        public void reportError(CompilationError ce, String prefix) {
    147147                ISourceLocation loc = ce.getLocation();
     148                if(prefix == null)
     149                        prefix = "";
     150                else
     151                        prefix = prefix + ": ";
     152                reportError(prefix + ce.getMarkerMessage(), loc, ce.getMarkerType());
     153                ce.printStackTrace();
     154        }
     155
     156        public void reportError(String message, ISourceLocation loc, String markerType) {
     157                reportError(message, loc, markerType, IMarker.SEVERITY_ERROR);
     158        }
     159        public void reportError(String message, ISourceLocation loc, String markerType, int severity) {
    148160                if(loc != null) {
    149                         if(prefix == null)
    150                                 prefix = "";
    151                         else
    152                                 prefix = prefix + ": ";
    153161                        URI uri = loc.getURI();
    154162                        IFile file = ProjectURIResolver.getFile(uri);
     
    156164                                int start = loc.getOffset();
    157165                                int end = loc.getOffset()+loc.getLength();
    158                                 for(IMarker m : file.findMarkers(ce.getMarkerType(), false, IResource.DEPTH_INFINITE)) {
     166                                for(IMarker m : file.findMarkers(markerType, false, IResource.DEPTH_INFINITE)) {
    159167                                        if(m.getAttribute(IMarker.CHAR_START, -1) == start
    160168                                                        && m.getAttribute(IMarker.CHAR_END, -1) == end
    161                                                         && m.getAttribute(IMarker.MESSAGE, "").equals(prefix + ce.getMarkerMessage()));
     169                                                        && m.getAttribute(IMarker.MESSAGE, "").equals(message))
    162170                                                return;
    163171                                }
    164                                 IMarker marker = file.createMarker(ce.getMarkerType());
     172                                IMarker marker = file.createMarker(markerType);
    165173                                marker.setAttribute(IMarker.CHAR_START, start);
    166174                                marker.setAttribute(IMarker.CHAR_END, end);
    167                                 marker.setAttribute(IMarker.MESSAGE, prefix + ce.getMarkerMessage());
     175                                marker.setAttribute(IMarker.MESSAGE, message);
    168176                                marker.setAttribute(IMarker.LOCATION, "Line " + loc.getBeginLine() + ", column " + loc.getBeginColumn());
    169                                 marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
     177                                marker.setAttribute(IMarker.SEVERITY, severity);
    170178                                marker.setAttribute(IMarker.TRANSIENT, true);
    171179                                return;
     
    173181                        }
    174182                }
    175                 ce.printStackTrace();
    176183        }
    177184}
  • trunk/magnolia-eclipse/src/org/magnolialang/xatree/TreeImplodeVisitor.java

    r453 r459  
    4747                IConstructor result = (IConstructor)TreeAdapter.getAlternatives(tree).iterator().next();
    4848
    49                 return result;
     49                return (IConstructor) result.accept(this);
    5050        }
    5151
Note: See TracChangeset for help on using the changeset viewer.