public VariableDescription(AALocalDecl localDecl, VariableTypes type) { Name = localDecl.GetName().Text; Type = Util.TypeToString(localDecl.GetType()); switch (type) { case VariableTypes.LocalVariable: PlacementPrefix = "Local"; break; case VariableTypes.Parameter: PlacementPrefix = "Parameter"; break; case VariableTypes.StructVariable: PlacementPrefix = "Struct field"; break; default: PlacementPrefix = ""; break; } VariableType = type; Const = localDecl.GetConst() != null; IsStatic = localDecl.GetStatic() != null; Visibility = localDecl.GetVisibilityModifier(); realType = (PType) localDecl.GetType().Clone(); init = localDecl.GetInit(); Line = localDecl.GetName().Line; Position = TextPoint.FromCompilerCoords(localDecl.GetName()); }
public override void CaseAALocalDecl(AALocalDecl node) { InAALocalDecl(node); if (node.GetInit() != null) { node.GetInit().Apply(this); } if (node.GetName() != null) { node.GetName().Apply(this); } if (node.GetType() != null) { node.GetType().Apply(this); } if (node.GetConst() != null) { node.GetConst().Apply(this); } if (node.GetOut() != null) { node.GetOut().Apply(this); } if (node.GetRef() != null) { node.GetRef().Apply(this); } if (node.GetStatic() != null) { node.GetStatic().Apply(this); } if (node.GetVisibilityModifier() != null) { node.GetVisibilityModifier().Apply(this); } OutAALocalDecl(node); }
public override void OutAALocalDecl(AALocalDecl node) { if (node.GetInit() != null) { PType from = data.ExpTypes[node.GetInit()]; PType to = node.GetType(); if (!Assignable(from, to)) { if (ImplicitAssignable(from, to)) { ANamedType namedTo = (ANamedType)to; ACastExp cast = new ACastExp(new TLParen("("), new ANamedType(new TIdentifier(((AAName)namedTo.GetName()).AsString()), null), node.GetInit()); node.SetInit(cast); OutACastExp(cast); to = from; } else errors.Add(new ErrorCollection.Error(node.GetName(), currentSourceFile, LocRM.GetString("ErrorText151") + Util.TypeToString(from) + LocRM.GetString("ErrorText152") + Util.TypeToString(to))); } } //If the return type or the type of any formals is a private struct, and the method is a public context, give an error if (node.Parent() is AStructDecl) { AStructDecl pStruct = Util.GetAncestor<AStructDecl>(node); //Is public context if ( pStruct.GetVisibilityModifier() is APublicVisibilityModifier && !(node.GetVisibilityModifier() is APrivateVisibilityModifier)) { PType type = node.GetType(); int i = 0; FindPrivateTypes finder = new FindPrivateTypes(data); type.Apply(finder); if (finder.PrivateTypes.Count > 0) { List<ErrorCollection.Error> subErrors = new List<ErrorCollection.Error>(); List<PDecl> usedDecls = new List<PDecl>(); foreach (ANamedType namedType in finder.PrivateTypes) { if (data.StructTypeLinks.ContainsKey(namedType)) { AStructDecl decl = data.StructTypeLinks[namedType]; if (usedDecls.Contains(decl)) continue; usedDecls.Add(decl); subErrors.Add(new ErrorCollection.Error(decl.GetName(), LocRM.GetString("ErrorText64"))); } else if (data.DelegateTypeLinks.ContainsKey(namedType)) { AMethodDecl decl = data.DelegateTypeLinks[namedType]; if (usedDecls.Contains(decl)) continue; usedDecls.Add(decl); subErrors.Add(new ErrorCollection.Error(decl.GetName(), LocRM.GetString("ErrorText154"))); } } errors.Add(new ErrorCollection.Error(node.GetName(), LocRM.GetString("ErrorText155"), false, subErrors.ToArray())); } } } base.OutAALocalDecl(node); }