public TypeSpecifier(string name, TypeKind kind, TypedNodeList typeParameters, Location location) : base(location) { this.name = name; this.kind = kind; this.typeParameters = typeParameters; }
public override void VisitAssign(AssignStatement assign) { TypeData lhsType; Argument arg = currentRoutine.GetArgument(assign.Name); if (arg != null) { if (arg.NodeType.IsByRef) lhsType = arg.NodeType.ElementType; else lhsType = arg.NodeType; } else { LocalVariable local = localVariableStack.GetLocal(assign.Name); if (local != null) { if (local.IsTypecaseVariable) { report.Error(assign.Location, "it is illegal " + "to assign to the typecase variable"); return; } lhsType = local.LocalType; } else { Expression self = new SelfExpression(assign.Location); ModalExpression arg1 = new ModalExpression(ArgumentMode.In, assign.Value, assign.Value.Location); TypedNodeList args = new TypedNodeList(arg1); assign.Call = new CallExpression(self, assign.Name, args, assign.Location); assign.Call.HasValue = false; assign.Call.Accept(this); if (assign.Call.NodeType == null) return; ParameterInfo[] parameters = typeManager.GetParameters(assign.Call.Method); lhsType = typeManager.GetTypeData(parameters[0].ParameterType); } } if (assign.Value is VoidExpression) { assign.Value.NodeType = lhsType; } else { // NodeType may be already set by DeclarationStatement if (assign.Value.NodeType == null) assign.Value.Accept(this); if (assign.Value.NodeType == null) return; if (!assign.Value.NodeType.IsSubtypeOf(lhsType)) { report.Error(assign.Location, "{0} is not a subtype of {1}", assign.Value.NodeType.FullName, lhsType.FullName); return; } } }
public virtual string GetMethodInfo(TypeData receiverType, string name, TypedNodeList arguments, TypeData returnType) { string methodInfo = receiverType.FullName + "::" + name; if (arguments.Length > 0) { methodInfo += "("; foreach (TypedNode arg in arguments) { if (arg != arguments.First) methodInfo += ","; methodInfo += arg.NodeType.FullName; } methodInfo += ")"; } if (returnType != null && !returnType.IsVoid) methodInfo += ":" + returnType.Name; return methodInfo; }
protected override void InitArguments() { int index = 1; int moveNextPos = 1; moveNextArguments = new TypedNodeList(); argumentTable = new Hashtable(); foreach (Argument arg in Arguments) { arg.Index = index++; if (arg.Mode != ArgumentMode.Once) { Argument ma = (Argument) arg.Clone(); ma.Index = moveNextPos++; moveNextArguments.Append(ma); argumentTable.Add(ma.Name, ma); } } }
public IterDefinition(string name, TypedNodeList arguments, TypeSpecifier returnType, StatementList statementList, RoutineModifier modifier, Location location) : base(name, arguments, returnType, statementList, modifier, location) { typeBuilder = null; typeParameters = null; boundType = null; self = null; current = null; currentPosition = null; constructor = null; moveNext = null; getCurrent = null; creator = null; localVariables = new Hashtable(); resumePoints = new ArrayList(); resumePoints.Add(new ResumePoint()); InitArguments(); bridgeMethods = new ArrayList(); }
public ClassDefinition(string name, ClassKind kind, TypedNodeList typeParameters, TypedNodeList supertypes, TypedNodeList subtypes, Location location) : base(location) { this.name = name; this.kind = kind; this.typeParameters = typeParameters; this.supertypes = supertypes; this.subtypes = subtypes; typeBuilder = null; typeData = null; constructor = null; staticConstructor = null; staticConstructorIL = null; adapters = new ArrayList(); }
public RoutineDefinition(string name, TypedNodeList arguments, TypeSpecifier returnType, StatementList statementList, RoutineModifier modifier, Location location) : base(name, arguments, returnType, location) { this.statementList = statementList; this.modifier = modifier; }
public virtual bool Match(string name, TypedNodeList arguments, bool hasReturnValue) { if (Name.ToLower() != name.ToLower()) return false; if (!ReturnType.IsVoid != hasReturnValue) return false; return Match(arguments); }
public CallExpression(Expression receiver, string name, TypedNodeList arguments, bool flip, Location location) : base(location) { this.receiver = receiver; typeSpecifier = null; this.name = name; this.arguments = arguments; this.flip = flip; method = null; isBuiltin = false; }
protected virtual TypedNodeList GetIterCreatorArguments(TypedNodeList arguments) { TypedNodeList args = new TypedNodeList(); foreach (Argument arg in arguments) { if (arg.Mode == ArgumentMode.Once) { Argument a = (Argument) arg.Clone(); a.Mode = ArgumentMode.In; args.Append(a); } } return args; }
protected virtual MethodBuilder DefineWriter(TypeBuilder type, string name, MethodAttributes attributes, TypeSpecifier attrType) { Argument arg = new Argument(ArgumentMode.In, "value", attrType, Location.Null); arg.Index = 1; arg.NodeType = attrType.NodeType; TypedNodeList args = new TypedNodeList(arg); CheckMethodConfliction(typeManager.GetTypeData(type), name, typeManager.VoidType, new TypedNodeList()); return DefineMethod(type, name, attributes, typeManager.VoidType, args); }
protected virtual MethodBuilder DefineMethod(TypeBuilder type, string name, MethodAttributes attributes, TypeData returnType, TypedNodeList arguments) { MethodBuilder method = type.DefineMethod(name, attributes, returnType.RawType, arguments.NodeTypes); ParameterInfo[] parameters = new ParameterInfo[arguments.Length]; ArrayList parameterList = new ArrayList(); foreach (Argument arg in arguments) { ParameterAttributes attrs = 0; switch (arg.Mode) { case ArgumentMode.Out: attrs |= ParameterAttributes.Out; break; case ArgumentMode.InOut: attrs |= ParameterAttributes.In; attrs |= ParameterAttributes.Out; break; } ParameterBuilder pb = method.DefineParameter(arg.Index, attrs, arg.Name); Type[] cparamTypes = new Type[] { typeof(ArgumentMode) }; ConstructorInfo constructor = typeof(ArgumentModeAttribute).GetConstructor(cparamTypes); CustomAttributeBuilder cbuilder = new CustomAttributeBuilder(constructor, new object[] { arg.Mode }); pb.SetCustomAttribute(cbuilder); parameters[arg.Index - 1] = new Parameter(pb, arg.NodeType.RawType, method); ArgumentModeAttribute attr = new ArgumentModeAttribute(arg.Mode); typeManager.AddCustomAttribute(parameters[arg.Index - 1], attr); UserDefinedParameterData paramData = new UserDefinedParameterData(typeManager, parameters[arg.Index - 1], arg.Mode); parameterList.Add(paramData); } UserDefinedMethodData methodData = typeManager.AddMethod(type, method); typeManager.AddParameters(method, parameters); methodData.Parameters = parameterList; return method; }
protected virtual ArrayList CheckMethodConformance(TypeData type, string name, TypeData returnType, TypedNodeList arguments, ArrayList ancestorMethods) { MethodSignature sig = new MethodSignature(type, name, returnType, arguments); ArrayList conformableMethods = new ArrayList(); foreach (MethodData m in ancestorMethods) { if (sig.ConformTo(m)) conformableMethods.Add(m); } foreach (MethodData m in conformableMethods) { ancestorMethods.Remove(m); } return conformableMethods; }
protected virtual void CheckMethodConfliction(TypeData type, string name, TypeData returnType, TypedNodeList arguments) { MethodSignature sig = new MethodSignature(type, name, returnType, arguments); foreach (MethodData m in type.Methods) { if (m.ConflictWith(sig)) { string msg = "The signature: " + sig + " conflicts with the earlier feature signature: " + m; throw new MethodConflictionException(msg); } } }
protected virtual void SetupIter(IterCallExpression iter, MethodData method, TypeData receiverType) { if (!method.MethodInfo.IsPublic && currentClass.TypeData != receiverType) { report.Error(iter.Location, "cannot call private iterator {0}", iter.Name); return; } iter.IsBuiltin = method.IsBuiltin; MethodData creator = method.IterCreator; iter.Method = creator.MethodInfo; iter.NodeType = method.ReturnType; if (iter.Receiver == null && (iter.IsBuiltin || !method.MethodInfo.IsStatic)) { iter.Receiver = new VoidExpression(iter.Location); iter.Receiver.NodeType = receiverType; } TypeData iterType = creator.ReturnType; string localName = getTemporallyName(); iter.Local = localVariableStack.AddLocal(localName, iterType); iter.CreatorArguments = new TypedNodeList(); TypedNodeList moveNextArguments = new TypedNodeList(); ModalExpression receiver = new ModalExpression(ArgumentMode.In, (Expression) iter.Receiver.Clone(), iter.Receiver.Location); ParameterInfo[] parameters = typeManager.GetParameters(method.MethodInfo); int i; if (iter.IsBuiltin) i = 1; else i = 0; foreach (ModalExpression arg in iter.Arguments) { ParameterInfo param = parameters[i++]; if (arg.NodeType == null) // void expression arg.NodeType = typeManager.GetTypeData(param.ParameterType); ArgumentMode mode = typeManager.GetArgumentMode(param); if (mode == ArgumentMode.Once) { ModalExpression me = (ModalExpression) arg.Clone(); me.Mode = ArgumentMode.In; iter.CreatorArguments.Append(me); } else { moveNextArguments.Append((ModalExpression) arg.Clone()); } } LocalExpression moveNextReceiver = new LocalExpression(iter.Local.Name, iter.Location); iter.MoveNext = new CallExpression(moveNextReceiver, "MoveNext", moveNextArguments, iter.Location); iter.MoveNext.Accept(this); if (!iter.NodeType.IsVoid) { LocalExpression getCurrentReceiver = new LocalExpression(iter.Local.Name, iter.Location); iter.GetCurrent = new CallExpression(getCurrentReceiver, "GetCurrent", new TypedNodeList(), iter.Location); iter.GetCurrent.Accept(this); } }
public virtual bool Match(TypedNodeList arguments) { if (Parameters.Count != arguments.Length) return false; int pos = 0; foreach (ModalExpression arg in arguments) { ParameterData param = (ParameterData) Parameters[pos++]; TypeData paramType = param.ParameterType; switch (arg.Mode) { case ArgumentMode.In: case ArgumentMode.Once: if (paramType.IsByRef) { return false; } if (arg.NodeType == null) continue; if (!arg.NodeType.IsSubtypeOf(paramType)) return false; break; case ArgumentMode.Out: if (!paramType.IsByRef || param.Mode != ArgumentMode.Out) return false; TypeData eltType = paramType.ElementType; if (!eltType.IsSubtypeOf(arg.NodeType) || eltType.IsValueType && !arg.NodeType.IsValueType) return false; break; case ArgumentMode.InOut: if (!paramType.IsByRef || param.Mode != ArgumentMode.InOut) return false; if (arg.NodeType != paramType.ElementType) return false; break; } } return true; }
public CallExpression(Expression receiver, string name, TypedNodeList arguments) : this(receiver, name, arguments, false, Location.Null) { }
public MethodSignature(TypeData declaringType, string name, TypeData returnType, TypedNodeList arguments) { this.declaringType = declaringType; this.name = name; this.returnType = returnType; this.arguments = arguments; }
public CallExpression(TypeSpecifier typeSpecifier, string name, TypedNodeList arguments, Location location) : base(location) { receiver = null; this.typeSpecifier = typeSpecifier; this.name = name; this.arguments = arguments; flip = false; method = null; isBuiltin = false; }
public AbstractRoutineSignature(string name, TypedNodeList arguments, TypeSpecifier returnType, Location location) : base(location) { this.name = name; this.arguments = arguments; this.returnType = returnType; this.methodBuilder = null; InitArguments(); }
public CallExpression(TypeSpecifier typeSpecifier, string name, TypedNodeList arguments) : this(typeSpecifier, name, arguments, Location.Null) { }
public ClassDefinition(string name, ClassKind kind, TypedNodeList typeParameters, TypedNodeList supertypes, Location location) : this(name, kind, typeParameters, supertypes, null, location) { }
public IterCallExpression(Expression receiver, string name, TypedNodeList arguments, Location location) : base(receiver, name, arguments, location) { }
public AbstractIterSignature(string name, TypedNodeList arguments, TypeSpecifier returnType, Location location) : base(name, arguments, returnType, location) { typeBuilder = null; constructor = null; moveNext = null; getCurrent = null; moveNextArguments = null; creator = null; InitArguments(); }
public NewExpression(TypeSpecifier typeSpecifier, TypedNodeList arguments, Location location) : base(location) { this.typeSpecifier = typeSpecifier; this.arguments = arguments; this.constructor = null; }
public override void VisitCase(CaseStatement caseStmt) { caseStmt.Test.Accept(this); caseStmt.TestName = getTemporallyName(); localVariableStack.AddLocal(caseStmt.TestName, caseStmt.Test.NodeType); foreach (CaseWhen when in caseStmt.WhenPartList) { foreach (Expression value in when.ValueList) { LocalExpression test = new LocalExpression(caseStmt.TestName, value.Location); ModalExpression arg = new ModalExpression(ArgumentMode.In, value, value.Location); TypedNodeList args = new TypedNodeList(arg); CallExpression call = new CallExpression(test, "is_eq", args, value.Location); call.Accept(this); if (call.NodeType == typeManager.BoolType) { when.TestCallList.Append(call); } else { if (call.NodeType != null) { report.Error(value.Location, "no match for {0}::is_eq({1}):BOOL", caseStmt.Test.NodeType.FullName, value.NodeType.FullName); } } } when.ThenPart.Accept(this); } if (caseStmt.ElsePart != null) caseStmt.ElsePart.Accept(this); }
public CaseWhen(TypedNodeList valueList, StatementList thenPart, Location location) : base(location) { this.valueList = valueList; this.thenPart = thenPart; this.testCallList = new TypedNodeList(); }