Ticket #152: implicit-dependency-refs.patch
File implicit-dependency-refs.patch, 6.8 KB (added by hopscc, 12 years ago) |
---|
-
Source/Compiler.cobra
782 782 _referenceVerbosity = .options.getDefault('verbosity-ref', 0) 783 783 return _referenceVerbosity 784 784 785 var _willReadDependencies = false785 var _willReadDependencies = true # false to suppress implicit dependency refs 786 786 787 787 def indentPrint 788 788 # see .loadReference which sets up the indented writer -
Source/NameSpace.cobra
29 29 var _subNameSpacesByName as Dictionary<of String, NameSpace> 30 30 var _subNameSpacesList as List<of NameSpace> 31 31 var _useDirectives as List<of UseDirective> 32 32 33 var _wasAccessed = false 34 33 35 cue init(unifiedNameSpace as NameSpace, name as String) 34 36 .init(TokenFix.empty, name) 35 37 _unifiedNameSpace = unifiedNameSpace … … 98 100 99 101 get useDirectives as UseDirective* 100 102 return _useDirectives 101 103 104 get wasAccessed as bool 105 """True if (unified) namespace had successful search done through it.""" 106 if not .isUnified, return _unifiedNameSpace.wasAccessed 107 return _wasAccessed 108 102 109 def addMinFields 103 110 base.addMinFields 104 111 .addField('subCount', _subNameSpacesList.count) … … 111 118 .addField('unifiedNameSpace', _unifiedNameSpace) 112 119 113 120 var _fullName as String? # TODO: put in .fullName property when that is supported 114 121 115 122 get fullName as String 116 123 ensure 117 124 not .isRoot implies .name in result … … 321 328 # our decl? 322 329 # TODO: should this come before checking our name? what does C# do? 323 330 x = .declForName(name) 324 if x, return x 331 if x 332 _wasAccessed = true 333 return x 325 334 /# 326 335 # wrong. see ticket:128 327 336 # a parent namespace? -
Source/BackEndClr/SharpGenerator.cobra
147 147 for refer in .loadedReferences # don't take the library references from options, because the references can grow 148 148 if refer == 'Cobra.Lang.dll', continue # hack. remove at some point 2012-07-17 149 149 backEndOptions.add('[optChar]r:[refer]') 150 150 151 # Add in refs for any dependant assemblyModules accessed but not specified 152 if _willReadDependencies # was wired false in Compiler.cobra 153 for refer in _implicitRefs 154 backEndOptions.add('[optChar]r:[refer]') 155 156 151 157 debug = options.getDefault('debug', '') to String 152 158 if debug.length 153 159 # TODO: mono does not support full and pdbonly afaik … … 228 234 _deleteIntermediateFiles 229 235 230 236 _copyCoreClr(outName) 231 237 238 def _implicitRefs as Set<of String> 239 """Accumulate list of dll modules loaded whose namespace contents are referenced that arent in loaded references""" 240 implicitRefs = Set<of String>() 241 for m in .modules 242 if m inherits AssemblyModule 243 fileName = Path.getFileName(m.fileName) to ! 244 refName = fileName.before('.dll') 245 if _moduleRefUsed(refName, m.topNameSpace) and fileName not in .loadedReferences 246 if .verbosity, print 'adding implicit ref [fileName]' 247 implicitRefs.add(fileName) 248 return implicitRefs 249 250 def _moduleRefUsed(refName as String, ns as NameSpace) as bool 251 names = refName.split(c'.') 252 thing as IContainer? = ns 253 for name in names 254 possible = thing.declForName(name) #shld be nil or a NameSpace 255 if not possible, return false 256 if possible inherits IContainer 257 thing = possible 258 return (thing to NameSpace).wasAccessed 259 232 260 def _copyCoreClr(outName as String) 233 261 if not .options.boolValue('copy-core'), return 234 262 sourceDir = Path.getDirectoryName(Assembly.getEntryAssembly.location) ? '' -
Source/BackEndClr/ScanClrType.cobra
76 76 if referredAss is nil, return couldNotFindMsg 77 77 reference += if(referredAss.location.endsWith('.exe'), '.exe', '.dll') 78 78 if referredAss 79 if _willReadDependencies # wired false in Compiler.cobra 80 for dependency in referredAss.getReferencedAssemblies 81 if rv 82 print '>> Loading dependency: [dependency]' 83 .indentPrint 84 try 85 _loadAssemblyNamed(dependency) 86 finally 87 .outdentPrint 88 print '<< Loading dependency: [dependency]' 89 else 90 _loadAssemblyNamed(dependency) 79 if _willReadDependencies # was wired false in Compiler.cobra 80 _loadAssemblyDependencies(referredAss, rv) 91 81 if rv, print 'Will read assembly: [referredAss]' 92 82 try 93 83 _readAssembly(referredAss, reference <> 'Cobra.Core.dll') … … 139 129 msg = 'Could not open assembly "[assName]" due to: [exc.getType.name]: [exc.message]' 140 130 if rv, print msg 141 131 throw SourceException(msg) 142 if _willReadDependencies # wired false in Compiler.cobra 143 for dependency in ass.getReferencedAssemblies 144 if rv 145 print '>> Loading dependency: [dependency]' 146 .indentPrint 147 try 148 _loadAssemblyNamed(dependency) 149 finally 150 .outdentPrint 151 print '<< Loading dependency: [dependency]' 132 if _willReadDependencies # was wired false in Compiler.cobra 133 _loadAssemblyDependencies(ass to !, rv) 152 134 try 153 135 .clrReadAssembly(ass to !) 154 136 catch readExc as Exception 155 137 if rv, print 'Caught exception during read assembly: [readExc]' 156 138 throw 157 139 140 def _loadAssemblyDependencies(referredAss as Assembly, rv as int) 141 for dependency in referredAss.getReferencedAssemblies 142 if rv 143 print '>> Loading dependency: [dependency]' 144 .indentPrint 145 try 146 __loadAssemblyNamed(dependency) 147 finally 148 .outdentPrint 149 print '<< Loading dependency: [dependency]' 150 else 151 #print '<< [referredAss.getName.name] has dependency [dependency.name]' 152 if dependency.name not in ['mscorlib', 'System'] 153 __loadAssemblyNamed(dependency) 154 158 155 var __willLoadReflectionOnly as bool? 159 156 160 157 def _willLoadReflectionOnly as bool -
Tests/510-implicit-dependency.cobra
1 # previously needed explicit ref for System.Drawing dependency 2 use System.Windows.Forms 3 use System.Drawing 4 5 # failed with next line commented 6 #@args -ref:System.Drawing 7 8 class Program 9 10 def main is shared 11 print Color.red