Merge pull request #1 from nyu-compiler-construction/apoorva/semantic
	
		
	
				
					
				
			Added semantic check for duplicate local variable declarationmaster
						commit
						a4419d0625
					
				@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					# Compiler Construction PA2 Worklog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Team:
 | 
				
			||||||
 | 
					**Apoorva Ranade**(ar6496)   **Sanjar Ahmadov**(sa5640)   **Yinqi Sun**(ys3540)
 | 
				
			||||||
 | 
					<br>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Passes:
 | 
				
			||||||
 | 
					   - 
 | 
				
			||||||
 | 
					## Recovery:
 | 
				
			||||||
 | 
					 -  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Challenges:
 | 
				
			||||||
 | 
					 -  
 | 
				
			||||||
 | 
					## Improvements: 
 | 
				
			||||||
 | 
					 - Added more tests to rigorously check program flow and indentation.
 | 
				
			||||||
@ -0,0 +1,56 @@
 | 
				
			|||||||
 | 
					package chocopy.common.analysis.types;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import chocopy.common.astnodes.ClassType;
 | 
				
			||||||
 | 
					import chocopy.common.astnodes.Identifier;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.annotation.JsonCreator;
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.annotation.JsonProperty;
 | 
				
			||||||
 | 
					import chocopy.common.analysis.SymbolTable;
 | 
				
			||||||
 | 
					import java.util.Objects;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Represents the semantic value of a simple class reference. */
 | 
				
			||||||
 | 
					public class ClassVType extends ValueType {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** The name of the class. */
 | 
				
			||||||
 | 
					    public final String className;
 | 
				
			||||||
 | 
					    public SymbolTable<Type> scope;
 | 
				
			||||||
 | 
					    public ClassVType super_class;
 | 
				
			||||||
 | 
					    /** A class type for the class named CLASSNAME. */
 | 
				
			||||||
 | 
					    @JsonCreator
 | 
				
			||||||
 | 
					    public ClassVType(@JsonProperty String className) {
 | 
				
			||||||
 | 
					        this.className = className;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** A class type for the class referenced by CLASSTYPEANNOTATION. */
 | 
				
			||||||
 | 
					    public ClassVType(ClassType classTypeAnnotation) {
 | 
				
			||||||
 | 
					        this.className = classTypeAnnotation.className;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    @JsonProperty
 | 
				
			||||||
 | 
					    public String className() {
 | 
				
			||||||
 | 
					        return className;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean equals(Object o) {
 | 
				
			||||||
 | 
					        if (this == o) {
 | 
				
			||||||
 | 
					            return true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (o == null || getClass() != o.getClass()) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        ClassVType classType = (ClassVType) o;
 | 
				
			||||||
 | 
					        return Objects.equals(className, classType.className);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public int hashCode() {
 | 
				
			||||||
 | 
					        return Objects.hash(className);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public String toString() {
 | 
				
			||||||
 | 
					        return className;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -0,0 +1,49 @@
 | 
				
			|||||||
 | 
					package chocopy.common.analysis.types;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.fasterxml.jackson.annotation.JsonCreator;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Semantic information for a function or method. */
 | 
				
			||||||
 | 
					public class FuncValueType extends Type {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** Function's name. */
 | 
				
			||||||
 | 
					    //public final String name;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    /** Types of parameters. */
 | 
				
			||||||
 | 
					    public List<ValueType> parameters;
 | 
				
			||||||
 | 
					    /** Function's return type. */
 | 
				
			||||||
 | 
					    public final ValueType returnType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** Create a FuncType returning RETURNTYPE0, initially parameterless. */
 | 
				
			||||||
 | 
					    public FuncValueType(ValueType returnType0) {
 | 
				
			||||||
 | 
					        this(new ArrayList<>(), returnType0);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Create a FuncType for NAME0 with formal parameter types PARAMETERS0, returning type
 | 
				
			||||||
 | 
					     * RETURNTYPE0.
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @JsonCreator
 | 
				
			||||||
 | 
					    public FuncValueType(List<ValueType> parameters0, ValueType returnType0) {
 | 
				
			||||||
 | 
					        this.parameters = parameters0;
 | 
				
			||||||
 | 
					        this.returnType = returnType0;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public boolean isFuncType() {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** Return the type of the K-th parameter. */
 | 
				
			||||||
 | 
					    public ValueType getParamType(int k) {
 | 
				
			||||||
 | 
					        return parameters.get(k);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public String toString() {
 | 
				
			||||||
 | 
					        return "<function>";
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
					Loading…
					
					
				
		Reference in new issue