Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Language Features:

Compiler Features:
* Code Generator: Use ``calldatacopy`` instead of ``codecopy`` to zero out memory past input.
* AST: Add a new node for doxygen-style, structured documentation that can be received by contract, function, event and modifier definitions.


Bugfixes:
Expand Down
2 changes: 2 additions & 0 deletions liblangutil/Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ Token Scanner::scanSlash()
// doxygen style /// comment
Token comment;
m_skippedComments[NextNext].location.start = firstSlashPosition;
m_skippedComments[NextNext].location.source = m_source;
Comment thread
erak marked this conversation as resolved.
Resolved
comment = scanSingleLineDocComment();
m_skippedComments[NextNext].location.end = sourcePos();
m_skippedComments[NextNext].token = comment;
Expand All @@ -454,6 +455,7 @@ Token Scanner::scanSlash()
// we actually have a multiline documentation comment
Token comment;
m_skippedComments[NextNext].location.start = firstSlashPosition;
m_skippedComments[NextNext].location.source = m_source;
comment = scanMultiLineDocComment();
m_skippedComments[NextNext].location.end = sourcePos();
m_skippedComments[NextNext].token = comment;
Expand Down
18 changes: 9 additions & 9 deletions libsolidity/analysis/DocStringAnalyser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool DocStringAnalyser::visit(EventDefinition const& _event)

void DocStringAnalyser::checkParameters(
CallableDeclaration const& _callable,
DocumentedAnnotation& _annotation
StructurallyDocumentedAnnotation& _annotation
)
{
set<string> validParams;
Expand All @@ -95,8 +95,8 @@ void DocStringAnalyser::checkParameters(

void DocStringAnalyser::handleConstructor(
CallableDeclaration const& _callable,
Documented const& _node,
DocumentedAnnotation& _annotation
StructurallyDocumented const& _node,
StructurallyDocumentedAnnotation& _annotation
)
{
static set<string> const validTags = set<string>{"author", "dev", "notice", "param"};
Expand All @@ -106,8 +106,8 @@ void DocStringAnalyser::handleConstructor(

void DocStringAnalyser::handleCallable(
CallableDeclaration const& _callable,
Documented const& _node,
DocumentedAnnotation& _annotation
StructurallyDocumented const& _node,
StructurallyDocumentedAnnotation& _annotation
)
{
static set<string> const validTags = set<string>{"author", "dev", "notice", "return", "param"};
Expand All @@ -116,16 +116,16 @@ void DocStringAnalyser::handleCallable(
}

void DocStringAnalyser::parseDocStrings(
Documented const& _node,
DocumentedAnnotation& _annotation,
StructurallyDocumented const& _node,
StructurallyDocumentedAnnotation& _annotation,
set<string> const& _validTags,
string const& _nodeName
)
{
DocStringParser parser;
if (_node.documentation() && !_node.documentation()->empty())
if (_node.documentation() && !_node.documentation()->text()->empty())
{
if (!parser.parse(*_node.documentation(), m_errorReporter))
if (!parser.parse(*_node.documentation()->text(), m_errorReporter))
m_errorOccured = true;
_annotation.docTags = parser.tags();
}
Expand Down
14 changes: 7 additions & 7 deletions libsolidity/analysis/DocStringAnalyser.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ class DocStringAnalyser: private ASTConstVisitor

void checkParameters(
CallableDeclaration const& _callable,
DocumentedAnnotation& _annotation
StructurallyDocumentedAnnotation& _annotation
);

void handleConstructor(
CallableDeclaration const& _callable,
Documented const& _node,
DocumentedAnnotation& _annotation
StructurallyDocumented const& _node,
StructurallyDocumentedAnnotation& _annotation
);

void handleCallable(
CallableDeclaration const& _callable,
Documented const& _node,
DocumentedAnnotation& _annotation
StructurallyDocumented const& _node,
StructurallyDocumentedAnnotation& _annotation
);

void parseDocStrings(
Documented const& _node,
DocumentedAnnotation& _annotation,
StructurallyDocumented const& _node,
StructurallyDocumentedAnnotation& _annotation,
std::set<std::string> const& _validTags,
std::string const& _nodeName
);
Expand Down
66 changes: 54 additions & 12 deletions libsolidity/ast/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,30 @@ class VariableScope
std::vector<VariableDeclaration const*> m_localVariables;
};

/**
* The doxygen-style, structured documentation class that represents an AST node.
*/
class StructuredDocumentation: public ASTNode
{
public:
StructuredDocumentation(
int64_t _id,
SourceLocation const& _location,
ASTPointer<ASTString> const& _text
): ASTNode(_id, _location), m_text(_text)
{}

void accept(ASTVisitor& _visitor) override;
void accept(ASTConstVisitor& _visitor) const override;

/// @return A shared pointer of an ASTString.
/// Contains doxygen-style, structured documentation that is parsed later on.
ASTPointer<ASTString> const& text() const { return m_text; }

private:
ASTPointer<ASTString> m_text;
};

/**
* Abstract class that is added to each AST node that can receive documentation.
*/
Expand All @@ -362,6 +386,24 @@ class Documented
ASTPointer<ASTString> m_documentation;
};

/**
* Abstract class that is added to each AST node that can receive a structured documentation.
*/
class StructurallyDocumented
{
public:
virtual ~StructurallyDocumented() = default;
explicit StructurallyDocumented(ASTPointer<StructuredDocumentation> const& _documentation): m_documentation(_documentation) {}

/// @return A shared pointer of a FormalDocumentation.
/// Can contain a nullptr in which case indicates absence of documentation
ASTPointer<StructuredDocumentation> const& documentation() const { return m_documentation; }

protected:
ASTPointer<StructuredDocumentation> m_documentation;
};


/**
* Abstract class that is added to AST nodes that can be marked as not being fully implemented
*/
Expand All @@ -385,21 +427,21 @@ class ImplementationOptional
* document order. It first visits all struct declarations, then all variable declarations and
* finally all function declarations.
*/
class ContractDefinition: public Declaration, public Documented
class ContractDefinition: public Declaration, public StructurallyDocumented
{
public:
ContractDefinition(
int64_t _id,
SourceLocation const& _location,
ASTPointer<ASTString> const& _name,
ASTPointer<ASTString> const& _documentation,
ASTPointer<StructuredDocumentation> const& _documentation,
std::vector<ASTPointer<InheritanceSpecifier>> const& _baseContracts,
std::vector<ASTPointer<ASTNode>> const& _subNodes,
ContractKind _contractKind = ContractKind::Contract,
bool _abstract = false
):
Declaration(_id, _location, _name),
Documented(_documentation),
StructurallyDocumented(_documentation),
m_baseContracts(_baseContracts),
m_subNodes(_subNodes),
m_contractKind(_contractKind),
Expand Down Expand Up @@ -681,7 +723,7 @@ class OverrideSpecifier: public ASTNode
std::vector<ASTPointer<UserDefinedTypeName>> m_overrides;
};

class FunctionDefinition: public CallableDeclaration, public Documented, public ImplementationOptional
class FunctionDefinition: public CallableDeclaration, public StructurallyDocumented, public ImplementationOptional
{
public:
FunctionDefinition(
Expand All @@ -693,14 +735,14 @@ class FunctionDefinition: public CallableDeclaration, public Documented, public
Token _kind,
bool _isVirtual,
ASTPointer<OverrideSpecifier> const& _overrides,
ASTPointer<ASTString> const& _documentation,
ASTPointer<StructuredDocumentation> const& _documentation,
ASTPointer<ParameterList> const& _parameters,
std::vector<ASTPointer<ModifierInvocation>> const& _modifiers,
ASTPointer<ParameterList> const& _returnParameters,
ASTPointer<Block> const& _body
):
CallableDeclaration(_id, _location, _name, _visibility, _parameters, _isVirtual, _overrides, _returnParameters),
Documented(_documentation),
StructurallyDocumented(_documentation),
ImplementationOptional(_body != nullptr),
m_stateMutability(_stateMutability),
m_kind(_kind),
Expand Down Expand Up @@ -870,21 +912,21 @@ class VariableDeclaration: public Declaration
/**
* Definition of a function modifier.
*/
class ModifierDefinition: public CallableDeclaration, public Documented
class ModifierDefinition: public CallableDeclaration, public StructurallyDocumented
{
public:
ModifierDefinition(
int64_t _id,
SourceLocation const& _location,
ASTPointer<ASTString> const& _name,
ASTPointer<ASTString> const& _documentation,
ASTPointer<StructuredDocumentation> const& _documentation,
ASTPointer<ParameterList> const& _parameters,
bool _isVirtual,
ASTPointer<OverrideSpecifier> const& _overrides,
ASTPointer<Block> const& _body
):
CallableDeclaration(_id, _location, _name, Visibility::Internal, _parameters, _isVirtual, _overrides),
Documented(_documentation),
StructurallyDocumented(_documentation),
m_body(_body)
{
}
Expand Down Expand Up @@ -935,19 +977,19 @@ class ModifierInvocation: public ASTNode
/**
* Definition of a (loggable) event.
*/
class EventDefinition: public CallableDeclaration, public Documented
class EventDefinition: public CallableDeclaration, public StructurallyDocumented
{
public:
EventDefinition(
int64_t _id,
SourceLocation const& _location,
ASTPointer<ASTString> const& _name,
ASTPointer<ASTString> const& _documentation,
ASTPointer<StructuredDocumentation> const& _documentation,
ASTPointer<ParameterList> const& _parameters,
bool _anonymous = false
):
CallableDeclaration(_id, _location, _name, Visibility::Default, _parameters),
Documented(_documentation),
StructurallyDocumented(_documentation),
m_anonymous(_anonymous)
{
}
Expand Down
14 changes: 7 additions & 7 deletions libsolidity/ast/ASTAnnotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ struct DocTag
std::string paramName; ///< Only used for @param, stores the parameter name.
};

struct DocumentedAnnotation
struct StructurallyDocumentedAnnotation
{
virtual ~DocumentedAnnotation() = default;
virtual ~StructurallyDocumentedAnnotation() = default;
/// Mapping docstring tag name -> content.
std::multimap<std::string, DocTag> docTags;
};
Expand Down Expand Up @@ -101,7 +101,7 @@ struct TypeDeclarationAnnotation: DeclarationAnnotation
std::string canonicalName;
};

struct ContractDefinitionAnnotation: TypeDeclarationAnnotation, DocumentedAnnotation
struct ContractDefinitionAnnotation: TypeDeclarationAnnotation, StructurallyDocumentedAnnotation
{
/// List of functions without a body. Can also contain functions from base classes.
std::vector<FunctionDefinition const*> unimplementedFunctions;
Expand All @@ -122,15 +122,15 @@ struct CallableDeclarationAnnotation: DeclarationAnnotation
std::set<CallableDeclaration const*> baseFunctions;
};

struct FunctionDefinitionAnnotation: CallableDeclarationAnnotation, DocumentedAnnotation
struct FunctionDefinitionAnnotation: CallableDeclarationAnnotation, StructurallyDocumentedAnnotation
{
};

struct EventDefinitionAnnotation: CallableDeclarationAnnotation, DocumentedAnnotation
struct EventDefinitionAnnotation: CallableDeclarationAnnotation, StructurallyDocumentedAnnotation
{
};

struct ModifierDefinitionAnnotation: CallableDeclarationAnnotation, DocumentedAnnotation
struct ModifierDefinitionAnnotation: CallableDeclarationAnnotation, StructurallyDocumentedAnnotation
{
};

Expand All @@ -142,7 +142,7 @@ struct VariableDeclarationAnnotation: DeclarationAnnotation
std::set<CallableDeclaration const*> baseFunctions;
};

struct StatementAnnotation: ASTAnnotation, DocumentedAnnotation
struct StatementAnnotation: ASTAnnotation
Comment thread
erak marked this conversation as resolved.
Resolved
{
};

Expand Down
1 change: 1 addition & 0 deletions libsolidity/ast/ASTForward.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class PrimaryExpression;
class Identifier;
class ElementaryTypeNameExpression;
class Literal;
class StructuredDocumentation;

class VariableScope;

Expand Down
19 changes: 15 additions & 4 deletions libsolidity/ast/ASTJsonConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ bool ASTJsonConverter::visit(ContractDefinition const& _node)
{
setJsonNode(_node, "ContractDefinition", {
make_pair("name", _node.name()),
make_pair("documentation", _node.documentation() ? Json::Value(*_node.documentation()) : Json::nullValue),
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
make_pair("contractKind", contractKind(_node.contractKind())),
make_pair("abstract", _node.abstract()),
make_pair("fullyImplemented", _node.annotation().unimplementedFunctions.empty()),
Expand Down Expand Up @@ -349,7 +349,7 @@ bool ASTJsonConverter::visit(FunctionDefinition const& _node)
{
std::vector<pair<string, Json::Value>> attributes = {
make_pair("name", _node.name()),
make_pair("documentation", _node.documentation() ? Json::Value(*_node.documentation()) : Json::nullValue),
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
make_pair("kind", TokenTraits::toString(_node.kind())),
make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())),
make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
Expand Down Expand Up @@ -400,7 +400,7 @@ bool ASTJsonConverter::visit(ModifierDefinition const& _node)
{
std::vector<pair<string, Json::Value>> attributes = {
make_pair("name", _node.name()),
make_pair("documentation", _node.documentation() ? Json::Value(*_node.documentation()) : Json::nullValue),
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
make_pair("parameters", toJson(_node.parameterList())),
make_pair("virtual", _node.markedVirtual()),
Expand All @@ -427,7 +427,7 @@ bool ASTJsonConverter::visit(EventDefinition const& _node)
m_inEvent = true;
setJsonNode(_node, "EventDefinition", {
make_pair("name", _node.name()),
make_pair("documentation", _node.documentation() ? Json::Value(*_node.documentation()) : Json::nullValue),
make_pair("documentation", _node.documentation() ? toJson(*_node.documentation()) : Json::nullValue),
make_pair("parameters", toJson(_node.parameterList())),
make_pair("anonymous", _node.isAnonymous())
});
Expand Down Expand Up @@ -833,6 +833,17 @@ bool ASTJsonConverter::visit(Literal const& _node)
return false;
}

bool ASTJsonConverter::visit(StructuredDocumentation const& _node)
{
Json::Value text{*_node.text()};
std::vector<pair<string, Json::Value>> attributes = {
make_pair("text", text)
};
setJsonNode(_node, "StructuredDocumentation", std::move(attributes));
return false;
}



void ASTJsonConverter::endVisit(EventDefinition const&)
{
Expand Down
1 change: 1 addition & 0 deletions libsolidity/ast/ASTJsonConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class ASTJsonConverter: public ASTConstVisitor
bool visit(Identifier const& _node) override;
bool visit(ElementaryTypeNameExpression const& _node) override;
bool visit(Literal const& _node) override;
bool visit(StructuredDocumentation const& _node) override;

void endVisit(EventDefinition const&) override;

Expand Down
Loading