Skip to content

Commit

Permalink
Major update to sources - we now save soruces as they are instead of …
Browse files Browse the repository at this point in the history
…foobared, stripped. Resolved issues with import reference search
  • Loading branch information
0x19 committed Jul 25, 2024
1 parent a500c97 commit cb29622
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
4 changes: 4 additions & 0 deletions abi/state_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func (b *Builder) processStateVariable(stateVar *ir.StateVariable) *Method {
StateMutability: b.normalizeStateMutability(stateVar.GetStateMutability()),
}

/* if stateVar.GetTypeDescription() == nil {
utils.DumpNodeWithExit(stateVar)
}*/

typeName := b.resolver.ResolveType(stateVar.GetTypeDescription())

switch typeName {
Expand Down
2 changes: 1 addition & 1 deletion ast/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func parseImportPathsForSourceUnit(
}

if importCtx.As() != nil {
importNode.UnitAlias = importCtx.As().GetText()
importNode.As = importCtx.As().GetText()
}

if importCtx.SymbolAliases() != nil {
Expand Down
9 changes: 4 additions & 5 deletions ast/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,12 @@ func (r *Resolver) resolveEntrySourceUnit() {

// resolveImportDirectives resolves import directives in the AST.
func (r *Resolver) byImport(name string, baseNode Node[NodeType]) (int64, *TypeDescription) {

// In case any imports are available and they are not exported
// we are going to append them to the exported symbols.
for _, node := range r.ASTBuilder.currentImports {
if node.GetType() == ast_pb.NodeType_IMPORT_DIRECTIVE {
importNode := node.(*Import)

if baseNode.GetType() != ast_pb.NodeType_IMPORT_DIRECTIVE {
continue
}

if importNode.GetName() == name {
return importNode.GetId(), importNode.GetTypeDescription()
}
Expand Down Expand Up @@ -563,6 +558,10 @@ func (r *Resolver) byStructs(name string) (int64, *TypeDescription) {
name = strings.Split(name, ".")[1]
}

if strings.Contains(name, "[]") {
name = strings.ReplaceAll(name, "[]", "")
}

for _, node := range r.currentStructs {
structNode := node.(*StructDefinition)
if structNode.GetName() == name {
Expand Down
11 changes: 9 additions & 2 deletions ast/type_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,15 @@ func (t *TypeName) parseIdentifierPath(unit *SourceUnit[Node[ast_pb.SourceUnit]]
if len(ctx.AllIdentifier()) > 0 {
identifierCtx := ctx.Identifier(0)
t.PathNode = &PathNode{
Id: t.GetNextID(),
Name: identifierCtx.GetText(),
Id: t.GetNextID(),
Name: func() string {
if len(ctx.AllIdentifier()) == 1 {
return identifierCtx.GetText()
} else if len(ctx.AllIdentifier()) == 2 {
return fmt.Sprintf("%s.%s", identifierCtx.GetText(), ctx.Identifier(1).GetText())
}
return ""
}(),
Src: SrcNode{
Line: int64(ctx.GetStart().GetLine()),
Column: int64(ctx.GetStart().GetColumn()),
Expand Down
6 changes: 4 additions & 2 deletions sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,11 +750,13 @@ func (s *Sources) WriteToDir(path string) error {

// Write each SourceUnit's content to a file in the specified directory
for _, sourceUnit := range s.SourceUnits {
content := utils.SimplifyImportPaths(sourceUnit.Content)
// WARN: Left it here as a future - BIG NO NO - import paths will be skewed and won't able to parse
// properly + we won't be able to share sources with everyone else as-they-are...
// content := utils.SimplifyImportPaths(sourceUnit.Content)

filePath := filepath.Join(path, sourceUnit.Name+".sol")

if err := utils.WriteToFile(filePath, []byte(content)); err != nil {
if err := utils.WriteToFile(filePath, []byte(sourceUnit.Content)); err != nil {
return fmt.Errorf("failed to write source unit %s to file: %v", sourceUnit.Name, err)
}
}
Expand Down

0 comments on commit cb29622

Please sign in to comment.